phpbbs.announce.c
来自「linux/unix环境下的建站系统」· C语言 代码 · 共 1,615 行 · 第 1/3 页
C
1,615 行
if(!valid_fname(newfname)) { RETURN_LONG(-2); } if((fin = fopen(fpath, "r")) == NULL) { RETURN_LONG(-4); } snprintf(tmpfpath, PATHLEN, "tmp/%s.%d.editpost", getCurrentUser()->userid, getpid()); if((fout = fopen(tmpfpath, "w")) == NULL) { RETURN_LONG(-4); } fwrite(content, content_len, 1, fout); while((asize = -attach_fgets(buf, sizeof(buf), fin)) != 0) { if(asize > 0) { put_attach(fin, fout, asize); } } fclose(fin); fclose(fout); f_cp(tmpfpath, fpath, O_TRUNC); unlink(tmpfpath); if(strcmp(fname, newfname)) { snprintf(newfpath, PATHLEN, "%s/%s", path, newfname); if(dashf(newfpath) || dashd(newfpath)) { RETURN_LONG(-3); } f_mv(fpath, newfpath); } bzero(&me, sizeof(me)); me.path = path; me.level = PERM_BOARDS; a_loadnames(&me, getSession()); for(i=0; i<me.num; i++) { if(strcmp(fname, M_ITEM(&me,i)->fname) == 0) { strncpy(M_ITEM(&me,i)->fname, newfname, 80); M_ITEM(&me,i)->fname[79] = '\0'; sprintf(M_ITEM(&me,i)->title, "%-38.38s %s ", title, getCurrentUser()->userid); find = true; break; } } if(!find) { a_freenames(&me); RETURN_LONG(-5); } if(a_savenames(&me) != 0) { a_freenames(&me); RETURN_LONG(-6); } a_freenames(&me); RETURN_LONG(0);}/* deletebbs_ann_delete(string path, string fname);return: 0: success -1: path not found -2: record not found in .Names -3: a_savenames failed*/PHP_FUNCTION(bbs_ann_delete){ int ac, i; char *path, *fname, fpath[PATHLEN]; int path_len, fname_len; MENU me; bool find = false; ac = ZEND_NUM_ARGS(); if((ac != 2) || (zend_parse_parameters(2 TSRMLS_CC, "ss", &path, &path_len, &fname, &fname_len) != SUCCESS)) { WRONG_PARAM_COUNT; } if(!dashd(path)) { RETURN_LONG(-1); } snprintf(fpath, PATHLEN, "%s/%s", path, fname); if(dashd(fpath)) { my_f_rm(fpath); } else if(dashf(fpath)) { my_unlink(fpath); } bzero(&me, sizeof(me)); me.path = path; me.level = PERM_BOARDS; a_loadnames(&me, getSession()); for(i=0; i<me.num; i++) { if(strcmp(fname, M_ITEM(&me,i)->fname) == 0) { find = true; break; } } if(!find) { a_freenames(&me); RETURN_LONG(-2); } a_delitem(&me,i); if(a_savenames(&me) != 0) { a_freenames(&me); RETURN_LONG(-3); } a_freenames(&me); ann_write_bmlog(path); RETURN_LONG(0);}/* copy to clipboardbbs_ann_copy(string path, string fnames, long delsource);note: if fnames contains more than one filenames, use "," to seperate. delsource=0 means to copy, else means to cut.return: 0: success -1: cannot write clipboard file*/PHP_FUNCTION(bbs_ann_copy){ int ac; char *path, *fnames, clipfile[PATHLEN]; int path_len, fnames_len; long delsource; FILE *fp; char *ptr; ac = ZEND_NUM_ARGS(); if((ac != 3) || (zend_parse_parameters(3 TSRMLS_CC, "ssl", &path, &path_len, &fnames, &fnames_len, &delsource) != SUCCESS)) { WRONG_PARAM_COUNT; } snprintf(clipfile, PATHLEN, "tmp/clip/%s.announce", getCurrentUser()->userid); if((fp = fopen(clipfile, "w")) == NULL) { RETURN_LONG(-1); } fprintf(fp, "DelSource=%ld\n", delsource); fprintf(fp, "Path=%s\n", path); ptr = fnames; while(*fnames != '\0') { ptr = strchr(fnames, ','); if(ptr != NULL) { *ptr = '\0'; fprintf(fp, "Filename=%s\n", fnames); fnames = ptr + 1; } else { break; } } fclose(fp); RETURN_LONG(0);}/* paste from clipboardbbs_ann_paste(string path);note: path is the destination dirreturn: 0: success -1: path not found -2: source path not found -3: board not found -4: no bm perm in source board -5: error writing .Names*/PHP_FUNCTION(bbs_ann_paste){ int ac, i; char *dpath, clipfile[PATHLEN], buf[PATHLEN], spath[PATHLEN], sfpath[PATHLEN], dfpath[PATHLEN]; char fname[STRLEN], newfname[STRLEN], title[STRLEN], *ptr; int dpath_len; bool delsource = false, find, err = false; bool inann = true; FILE *fp; MENU sme, dme; char bname[STRLEN]; const struct boardheader *bp; struct fileheader fh; ac = ZEND_NUM_ARGS(); if((ac != 1) || (zend_parse_parameters(1 TSRMLS_CC, "s", &dpath, &dpath_len) != SUCCESS)) { WRONG_PARAM_COUNT; } if(!dashd(dpath)) { RETURN_LONG(-1); } snprintf(clipfile, PATHLEN, "tmp/clip/%s.announce", getCurrentUser()->userid); if((fp = fopen(clipfile, "r")) == NULL) { RETURN_LONG(0); } spath[0] = '\0'; bname[0] = '\0'; while(fgets(buf, sizeof(buf), fp) != NULL) { if((ptr = strchr(buf, '\n')) != NULL) *ptr = '\0'; if(strncmp(buf, "DelSource=OnBoard", 17) == 0) { inann = false; /* the files in clipboard is from a borad, not a announce dir */ continue; } else if(strncmp(buf, "DelSource=1", 11) == 0) { delsource = true; continue; } if(inann) /* clipboard contains files from another announce dir */ { if(strncmp(buf, "Path=", 5) == 0) { strncpy(spath, buf + 5, PATHLEN); if(dashd(spath)) { if(strcmp(spath, dpath) == 0) { fclose(fp); unlink(clipfile); RETURN_LONG(-1); } } else { fclose(fp); unlink(clipfile); RETURN_LONG(-2); } bzero(&sme, sizeof(sme)); sme.path = spath; sme.level = PERM_BOARDS; a_loadnames(&sme, getSession()); bzero(&dme, sizeof(dme)); dme.path = dpath; dme.level = PERM_BOARDS; a_loadnames(&dme, getSession()); } else if(spath[0] != '\0') { if(strncmp(buf, "Filename=", 9) == 0) { strncpy(fname, buf + 9, STRLEN); snprintf(sfpath, PATHLEN, "%s/%s", spath, fname); if(!(dashf(sfpath)||dashd(sfpath))) continue; snprintf(dfpath, PATHLEN, "%s/%s", dpath, fname); if(dashf(dfpath)||dashd(dfpath)) continue; if(delsource) f_mv(sfpath, dfpath); else f_cp(sfpath, dfpath, O_TRUNC); find = false; for(i=0; i<sme.num; i++) { if(strcmp(fname, M_ITEM(&sme,i)->fname) == 0) { find = true; break; } } if(find) { strncpy(title, M_ITEM(&sme,i)->title, STRLEN); if(delsource) a_delitem(&sme,i); } a_additem(&dme, title, fname, NULL, 0, 0); } } } else /* clipboard contains files from a board */ { if(strncmp(buf, "Board=", 6) == 0) { strncpy(bname, buf + 6, STRLEN); if((bp = getbcache(bname)) == NULL) { fclose(fp); unlink(clipfile); RETURN_LONG(-3); } strcpy(bname, bp->filename); if(!is_BM(bp, getCurrentUser())) { fclose(fp); unlink(clipfile); RETURN_LONG(-4); } bzero(&dme, sizeof(dme)); dme.path = dpath; dme.level = PERM_BOARDS; a_loadnames(&dme, getSession()); strcpy(title, "没有名字?"); } else if(bname[0] != '\0') { if(strncmp(buf, "Title=", 6) == 0) { snprintf(title, STRLEN, "%-38.38s %s ", buf + 6, getCurrentUser()->userid); } else if(strncmp(buf, "Filename=", 9) == 0) { strncpy(fname, buf + 9, STRLEN); setbfile(sfpath, bname, fname); if(!dashf(sfpath)) continue; strcpy(fh.filename, fname); ann_get_postfilename(newfname, &fh, &dme); snprintf(dfpath, PATHLEN, "%s/%s", dpath, newfname); f_cp(sfpath, dfpath, O_TRUNC); a_additem(&dme, title, newfname, NULL, 0, 0); } } } } fclose(fp); if(delsource && inann) { if(a_savenames(&sme) != 0) err = true; } if(a_savenames(&dme) != 0) err = true; if(inann) a_freenames(&sme); a_freenames(&dme); unlink(clipfile); if(err) { RETURN_LONG(-3); } else { ann_write_bmlog(dpath); RETURN_LONG(0); }}/* move itembbs_ann_move(string path, long oldnum, long newnum);return: 0: success -1: path not found -2: item not found -3: a_savesnames failed*/PHP_FUNCTION(bbs_ann_move){ int ac; char *path; int path_len, i; long oldnum, newnum; MENU me; ITEM *tmp; ac = ZEND_NUM_ARGS(); if((ac != 3) || (zend_parse_parameters(3 TSRMLS_CC, "sll", &path, &path_len, &oldnum, &newnum) != SUCCESS)) { WRONG_PARAM_COUNT; } if(oldnum == newnum) { RETURN_LONG(0); } if(!dashd(path)) { RETURN_LONG(-1); } bzero(&me, sizeof(me)); me.path = path; me.level = PERM_BOARDS; a_loadnames(&me, getSession()); if((oldnum > me.num) || (oldnum <= 0)) { RETURN_LONG(-2); } if(newnum <= 0) newnum = 1; if(newnum > me.num) newnum = me.num; oldnum--; newnum--; tmp = M_ITEM(&me,oldnum); if(oldnum > newnum) { for(i=oldnum; i>newnum; i--) M_ITEM(&me,i) = M_ITEM(&me,i-1); } else { for(i=oldnum; i<newnum; i++) M_ITEM(&me,i) = M_ITEM(&me,i+1); } M_ITEM(&me,newnum)=tmp; if(a_savenames(&me) != 0) { a_freenames(&me); RETURN_LONG(-3); } a_freenames(&me); ann_write_bmlog(path); RETURN_LONG(0);}/* BM functions of announce end here *//* Import path functions below * by pig2532@newsmth *//* read import path listarray bbs_ipath_list();return: array of import path list when success false when failed*/PHP_FUNCTION(bbs_ipath_list){ zval *item; char *ipath[ANNPATH_NUM], *ititle[ANNPATH_NUM]; int ipath_select = 0, i; time_t ipath_time = 0; if(ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } if(!HAS_PERM(getCurrentUser(), PERM_BOARDS)) { RETURN_FALSE; } load_import_path(ipath, ititle, &ipath_time, &ipath_select, getSession()); array_init(return_value); for(i=0; i<ANNPATH_NUM; i++) { MAKE_STD_ZVAL(item); array_init(item); add_assoc_string(item, "PATH", ipath[i], 1); add_assoc_string(item, "TITLE", ititle[i], 1); zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void*)&item, sizeof(zval*), NULL); } free_import_path(ipath, ititle, &ipath_time);}/* modify import pathbbs_ipath_modify(long num, string title, string path);return: 0: success -1: num not correct -2: no bm perm in that path*/PHP_FUNCTION(bbs_ipath_modify){ long num; char *title, *path; int title_len, path_len; char *ipath[ANNPATH_NUM], *ititle[ANNPATH_NUM]; int ipath_select = 0; time_t ipath_time = 0; path = NULL; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|s", &num, &title, &title_len, &path, &path_len) != SUCCESS) { WRONG_PARAM_COUNT; } if(!HAS_PERM(getCurrentUser(), PERM_BOARDS)) { RETURN_LONG(-2); } if((num < 1) || (num > ANNPATH_NUM)) { RETURN_LONG(-1); } if(path) if(path[0] != '\0') if(ann_traverse_check(path, getCurrentUser()) != 1) { RETURN_LONG(-2); } num--; load_import_path(ipath, ititle, &ipath_time, &ipath_select, getSession()); free(ititle[num]); ititle[num] = (char *)malloc(title_len + 1); strcpy(ititle[num], title); ititle[num][title_len] = '\0'; if(path) { free(ipath[num]); ipath[num] = (char *)malloc(path_len + 1); strcpy(ipath[num], path); ipath[num][path_len] = '\0'; } save_import_path(ipath, ititle, &ipath_time, getSession()); free_import_path(ipath, ititle, &ipath_time); RETURN_LONG(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?