phpbbs.post.c
来自「linux/unix环境下的建站系统」· C语言 代码 · 共 1,270 行 · 第 1/3 页
C
1,270 行
char *board,*filename, *tit, *target; int board_len,filename_len,tit_len,target_len; const struct boardheader *bh; char fname[STRLEN]; long big5,noansi; char title[512]; struct userec *u; int ret; if (ZEND_NUM_ARGS() != 6 || zend_parse_parameters(6 TSRMLS_CC, "ssssll", &board, &board_len,&filename, &filename_len, &tit, &tit_len, &target, &target_len, &big5, &noansi) != SUCCESS) { WRONG_PARAM_COUNT; } if( target[0] == 0 ) RETURN_LONG(-8); if( !strchr(target, '@') ){ if( getuser(target,&u) == 0) RETURN_LONG(-8); ret = check_mail_perm(getCurrentUser(), u); if (ret) { RETURN_LONG(-ret); } big5=0; noansi=0; } if (getbid(board, &bh) == 0) RETURN_LONG(-11); //"错误的讨论区"; if (!check_read_perm(getCurrentUser(), bh)) RETURN_LONG(-11); //您无权阅读本版; setbfile(fname, bh->filename, filename); if( !file_exist(fname) ) RETURN_LONG(-7); snprintf(title, 511, "%.50s(转寄)", tit); if( !strchr(target, '@') ){ mail_file(getCurrentUser()->userid, fname, u->userid, title,0, NULL); RETURN_LONG(1); }else{ if( big5 == 1) conv_init(getSession()); if( bbs_sendmail(fname, title, target, big5, noansi, getSession()) == 0){ RETURN_LONG(1); }else RETURN_LONG(-10); }}/** * 转贴文章 * int bbs_docross(string board,int id,string target,int out_go [,string filename, string title]); * return 0 :success * -1:源版面不存在 * -2:目标版面不存在 * -3:目标版面只读 * -4:无发文权限 * -5:被封禁 * -6:文件记录不存在 * -7:已经被转载过了 * -8:不能在板内转载 * -9:目标版面不支持附件 * -10:system error * @author: windinsn */PHP_FUNCTION(bbs_docross){ char *board,*target,*filename,*title; int board_len,target_len,filename_len,title_len; long id,out_go; const struct boardheader *src_bp; const struct boardheader *dst_bp; struct fileheader f; int ent; int fd; struct userec *u = NULL; char path[256],ispost[10]; int ac = ZEND_NUM_ARGS(); if (ac == 4) { if (zend_parse_parameters(4 TSRMLS_CC, "slsl", &board, &board_len, &id, &target, &target_len, &out_go) == FAILURE) { WRONG_PARAM_COUNT; } } else if (ac == 6) { /* cross mail by pig2532 */ if (zend_parse_parameters(6 TSRMLS_CC, "slslss", &board, &board_len, &id, &target, &target_len, &out_go, &filename, &filename_len, &title, &title_len) == FAILURE) { WRONG_PARAM_COUNT; } } else { WRONG_PARAM_COUNT; } u = getCurrentUser(); if (ac == 4) { src_bp = getbcache(board); if (src_bp == NULL) RETURN_LONG(-1); strcpy(board, src_bp->filename); if(!check_read_perm(u, src_bp)) RETURN_LONG(-1); } dst_bp = getbcache(target); if (dst_bp == NULL) RETURN_LONG(-2); strcpy(target, dst_bp->filename); if (!strcmp(board,target)) RETURN_LONG(-8); strcpy(ispost ,((dst_bp->flag & BOARD_OUTFLAG) && out_go)?"s":"l"); if(!check_read_perm(u, dst_bp)) RETURN_LONG(-2); if (true == checkreadonly(target)) RETURN_LONG(-3); //只读讨论区 if (!HAS_PERM(u,PERM_SYSOP)) { //权限检查 if (!haspostperm(u, target)) RETURN_LONG(-4); if (deny_me(u->userid, target)) RETURN_LONG(-5); } if (check_last_post_time(getSession()->currentuinfo)) { RETURN_LONG(-10); } if (ac == 4) { setbdir(DIR_MODE_NORMAL, path, board); if ((fd = open(path, O_RDWR, 0644)) < 0) RETURN_LONG(-10); if (!get_records_from_id(fd,id,&f,1,&ent)) { close(fd); RETURN_LONG(-6); //无法取得文件记录 } close(fd); #if 0 //disabled by atppp 20051228 if ((f.accessed[0] & FILE_FORWARDED) && !HAS_PERM(u, PERM_SYSOP)) RETURN_LONG(-7);#endif if ((f.attachment!=0)&&!(dst_bp->flag&BOARD_ATTACH)) RETURN_LONG(-9); setbfile(path, board, f.filename); if (post_cross(u, dst_bp, board, f.title, path, 0, 0, ispost[0], 0, getSession()) == -1) RETURN_LONG(-10); } else if (ac == 6) { setmailfile(path, getCurrentUser()->userid, filename); if (post_cross(u, dst_bp, target, title, path, 0, 1, ispost[0], 0, getSession()) == -1) RETURN_LONG(-10); } RETURN_LONG(0);}/** * int bbs_docommend(string board, int id, int confirmed); * * @param confirmed: when set false, only test if can recommend * * return 0: no error * -1: 无权限 * -2: 源版面不存在 * -3: 文件记录不存在 * -4: 本文章已经推荐过 * -5: 内部版面文章 * -6: 被停止了推荐的权力 * -7: 推荐出错 * -10: system err * * @author atppp */PHP_FUNCTION(bbs_docommend){#ifdef COMMEND_ARTICLE char *board; int board_len; long id,confirmed; struct userec *u; const struct boardheader *src_bp, *commend_bp; struct fileheader fileinfo; int ent; int fd; char path[256]; int ac = ZEND_NUM_ARGS(); if (ac != 3 || zend_parse_parameters(3 TSRMLS_CC, "sll", &board, &board_len, &id, &confirmed) == FAILURE) { WRONG_PARAM_COUNT; } u = getCurrentUser(); src_bp = getbcache(board); if (src_bp == NULL) RETURN_LONG(-1); strcpy(board, src_bp->filename); if(!check_read_perm(u, src_bp)) RETURN_LONG(-2); setbdir(DIR_MODE_NORMAL, path, board); if ((fd = open(path, O_RDWR, 0644)) < 0) RETURN_LONG(-10); if (!get_records_from_id(fd,id,&fileinfo,1,&ent)) { close(fd); RETURN_LONG(-3); //无法取得文件记录 } close(fd); commend_bp = getbcache(COMMEND_ARTICLE); if (commend_bp == NULL) { RETURN_LONG(-7); } if (!is_BM(commend_bp, u) && !is_BM(src_bp, u)) { if (strcmp(u->userid, fileinfo.owner)) RETURN_LONG(-1); } if (!HAS_PERM(getCurrentUser(), PERM_LOGINOK)) { RETURN_LONG(-1); } if ((fileinfo.accessed[1] & FILE_COMMEND) && !HAS_PERM(getCurrentUser(), PERM_SYSOP)) { RETURN_LONG(-4); } if( ! normal_board(board) ){ RETURN_LONG(-5); } if ( deny_me(u->userid, COMMEND_ARTICLE) ) { RETURN_LONG(-6); } if (confirmed) { if (post_commend(u, board, &fileinfo ) == -1) { RETURN_LONG(-7); } else { struct write_dir_arg dirarg; struct fileheader data; data.accessed[1] = FILE_COMMEND; init_write_dir_arg(&dirarg); dirarg.filename = path; dirarg.ent = ent; change_post_flag(&dirarg,DIR_MODE_NORMAL,src_bp, &fileinfo, FILE_COMMEND_FLAG, &data,false,getSession()); free_write_dir_arg(&dirarg); } } RETURN_LONG(0);#else RETURN_LONG(-1);#endif}PHP_FUNCTION(bbs_brcaddread){ char *board; int blen; long fid; const boardheader_t* bp; int bid; if (!strcmp(getCurrentUser()->userid, "guest")) { RETURN_NULL(); } if (zend_parse_parameters(2 TSRMLS_CC, "sl", &board, &blen, &fid) != SUCCESS) WRONG_PARAM_COUNT; if ((bid=getbid(board, &bp))==0){ RETURN_NULL(); }#ifdef HAVE_BRC_CONTROL brc_initial(getCurrentUser()->userid, bp->filename, getSession()); brc_add_read(fid, bid, getSession());#endif RETURN_NULL();}/** * 清除版面未读标记 * bbs_brcclear(string board) * windinsn * return true/false */PHP_FUNCTION(bbs_brcclear){ char *board; int board_len; const struct boardheader *pbh; struct userec *u; int bid; int ac = ZEND_NUM_ARGS(); if (ac != 1 || zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s" , &board, &board_len) == FAILURE) WRONG_PARAM_COUNT; u = getCurrentUser(); if (!u) RETURN_FALSE; bid = getbid(board, &pbh); if (bid == 0) RETURN_FALSE; if (!check_read_perm(u, pbh)) RETURN_FALSE; if (!strcmp(u->userid,"guest")) RETURN_TRUE;#ifdef HAVE_BRC_CONTROL brc_initial(u->userid, pbh->filename, getSession()); brc_clear(bid, getSession());#endif RETURN_TRUE;}#ifdef HAVE_BRC_CONTROLstatic int brcdump(struct boardheader *bh, int bid, void* arg){ char **dumpstr = (char **)arg; int n; unsigned int *pn; if (!public_board(bh)) return 0; sprintf(*dumpstr, "%4.4x", bid); *dumpstr += 4; brc_initial(getCurrentUser()->userid, bh->filename, getSession()); pn = getSession()->brc_cache_entry[getSession()->brc_currcache].list; for (n = 0; n < BRC_MAXNUM; n++) { if (*pn == 0) break; pn++; } sprintf(*dumpstr, "%4.4x", n); *dumpstr += 4; pn = getSession()->brc_cache_entry[getSession()->brc_currcache].list; for (n = 0; n < BRC_MAXNUM; n++) { if (*pn == 0) break; sprintf(*dumpstr, "%8.8x", *pn); *dumpstr += 8; pn++; } return 0;}#endifPHP_FUNCTION(bbs2_brcdump){#ifdef HAVE_BRC_CONTROL char dumpstr[MAXBOARD * (BRC_MAXNUM + 1) * 8 + 1]; char *dumpptr = dumpstr; *dumpptr = '\0'; if (!strcmp(getCurrentUser()->userid, "guest")) { RETURN_NULL(); } apply_bids(brcdump, &dumpptr); RETURN_STRING(dumpstr, 1);#endif}PHP_FUNCTION(bbs2_brcsync){#ifdef HAVE_BRC_CONTROL char *dumpstr; char *enddump; int dumpstr_len; int bid, j, id, n; int total = 0; const struct boardheader *bh; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s/" , &dumpstr, &dumpstr_len) == FAILURE) WRONG_PARAM_COUNT; if (!strcmp(getCurrentUser()->userid, "guest")) { RETURN_NULL(); } enddump = dumpstr + dumpstr_len;#define READ_NEXT(var, len) \ do { \ char tmp; \ if (enddump - dumpstr < len) goto brcsync_faint; \ tmp = *(dumpstr + len); \ *(dumpstr + len) = 0; \ var = (int)strtol(dumpstr, NULL, 16); \ dumpstr += len; \ *dumpstr = tmp; \ } while(0) while(dumpstr < enddump) { READ_NEXT(bid, 4); READ_NEXT(n, 4); if (n == 0) continue; if (n < 0 || n > BRC_MAXNUM) goto brcsync_faint; bh = getboard(bid); if (bh == NULL) goto brcsync_faint; if (!public_board(bh)) goto brcsync_faint; brc_initial(getCurrentUser()->userid, bh->filename, getSession()); for (j=0; j<n; j++) { READ_NEXT(id, 8); brc_add_read(id, bid, getSession()); } total += n; } RETURN_LONG(total);brcsync_faint: RETURN_NULL();#endif}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?