📄 phpbbs.board.c
字号:
MAKE_STD_ZVAL(element); array_init(element); add_assoc_string(element,"USERID","_wwwguest",1); inet_ntop(AF_INET, &wwwguest_shm->guest_entry[i].fromip, buf, IPLEN); add_assoc_string(element,"HOST",buf,1); zend_hash_index_update(Z_ARRVAL_P(users),j,(void*) &element, sizeof(zval*), NULL); j ++; } } } RETURN_LONG(j); }PHP_FUNCTION(bbs_boardonlines_for_rrdtool){ int totals[MAXBOARD][3]; uint16_t ret[MAXBOARD][4]; char b64[sizeof(ret)*2]; int i, nBoards; bzero(totals, sizeof(totals)); for (i=0;i<USHM_SIZE;i++) { struct user_info *ui; ui=get_utmpent(i+1); if (ui->active) { int b = ui->currentboard; if (b) { totals[b-1][0]++; if (ui->pid==1) totals[b-1][1]++; } } } for (i=0;i<MAX_WWW_GUEST;i++) { if (wwwguest_shm->use_map[i / 32] & (1 << (i % 32))) { int b=wwwguest_shm->guest_entry[i].currentboard; if (b) totals[b-1][2]++; } } nBoards = 0; for (i=0;i<MAXBOARD;i++) { const struct boardheader *b = getboard(i+1); if (!b->filename[0]) continue; if (!public_board(b)) continue; if (b->flag&BOARD_GROUP) continue; ret[nBoards][0]=htons(i+1); ret[nBoards][1]=htons(totals[i][0]); ret[nBoards][2]=htons(totals[i][1]); ret[nBoards][3]=htons(totals[i][2]); nBoards++; } to64frombits((unsigned char*)b64, (unsigned char *)ret, nBoards*8); RETURN_STRING(b64, 1);}PHP_FUNCTION(bbs_set_onboard){ int ac = ZEND_NUM_ARGS(); long boardnum,count; int oldboard; struct WWW_GUEST_S *guestinfo = NULL; if (ac != 2 || zend_parse_parameters(2 TSRMLS_CC, "ll", &boardnum, &count) == FAILURE) { WRONG_PARAM_COUNT; } if (getCurrentUser()==NULL) RETURN_FALSE; if (getSession()->currentuinfo==NULL) RETURN_FALSE; if (!strcmp(getCurrentUser()->userid,"guest")) { guestinfo=www_get_guest_entry(getSession()->utmpent); oldboard=guestinfo->currentboard; } else oldboard=getSession()->currentuinfo->currentboard; if (oldboard) board_setcurrentuser(oldboard, -1); board_setcurrentuser(boardnum, count); if (!strcmp(getCurrentUser()->userid,"guest")) { if (count>0) guestinfo->currentboard = boardnum; else guestinfo->currentboard = 0; } else { if (count>0) getSession()->currentuinfo->currentboard = boardnum; else getSession()->currentuinfo->currentboard = 0; } RETURN_TRUE;}/* * bbs_load_favboard()*/PHP_FUNCTION(bbs_load_favboard){ long select, mode=1; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &select, &mode) ==FAILURE) { WRONG_PARAM_COUNT; } getSession()->mybrd_list_t = 0; load_favboard(mode, getSession()); if(select>=0 && select<favbrd_list_t) { SetFav(select, getSession()); RETURN_LONG(0); } else RETURN_LONG(-1);}PHP_FUNCTION(bbs_is_favboard){ int ac = ZEND_NUM_ARGS(); long position; if(ac != 1 || zend_parse_parameters(1 TSRMLS_CC, "l" ,&position) == FAILURE){ WRONG_PARAM_COUNT; } RETURN_LONG(IsFavBoard(position-1, getSession(), 1, getSession()->favnow)); //position是bid,但是fav数据结构里头的是-1的. - atppp}PHP_FUNCTION(bbs_del_favboarddir){ int ac = ZEND_NUM_ARGS(); long select; long position; if(ac != 2 || zend_parse_parameters(2 TSRMLS_CC, "ll" , &select, &position) == FAILURE){ WRONG_PARAM_COUNT; } if(select < 0 || select >= FAVBOARDNUM) RETURN_LONG(-1); if(getSession()->nowfavmode != 1) RETURN_LONG(-1); if(position < 0 || position>= getSession()->mybrd_list[select].bnum) RETURN_LONG(-1); if(getSession()->mybrd_list[select].bid[position]<0) DelFavBoardDir(position,select, getSession()); else RETURN_LONG(-1); save_favboard(1, getSession()); RETURN_LONG(0);}PHP_FUNCTION(bbs_get_dirname){ int ac = ZEND_NUM_ARGS(); long select; char title[256]; if(ac != 1 || zend_parse_parameters(1 TSRMLS_CC, "l" , &select) == FAILURE){ WRONG_PARAM_COUNT; } if(select < 0 || select >= favbrd_list_t ) RETURN_LONG(0); FavGetTitle(select,title, getSession()); RETURN_STRING( title, 1);}PHP_FUNCTION(bbs_get_father){ int ac = ZEND_NUM_ARGS(); long select; if(ac != 1 || zend_parse_parameters(1 TSRMLS_CC, "l" , &select) == FAILURE){ WRONG_PARAM_COUNT; } RETURN_LONG( FavGetFather(select, getSession()) );}PHP_FUNCTION(bbs_del_favboard){ int ac = ZEND_NUM_ARGS(); long select; long position; if(ac != 2 || zend_parse_parameters(2 TSRMLS_CC, "ll" , &select, &position) == FAILURE){ WRONG_PARAM_COUNT; } if(getSession()->nowfavmode != 1) RETURN_LONG(-1); DelFavBoard(position, getSession()); save_favboard(1, getSession()); RETURN_LONG(0);}//add fav dirPHP_FUNCTION(bbs_add_favboarddir){ int ac = ZEND_NUM_ARGS(); int char_len; char *char_dname; if(ac != 1 || zend_parse_parameters(1 TSRMLS_CC,"s",&char_dname,&char_len) ==FAILURE){ WRONG_PARAM_COUNT; } if(char_len <= 20) { if(getSession()->nowfavmode != 1) RETURN_LONG(-1); addFavBoardDir(char_dname, getSession()); save_favboard(1, getSession()); } RETURN_LONG(char_len);}PHP_FUNCTION(bbs_add_favboard){ int ac = ZEND_NUM_ARGS(); int char_len; char *char_bname; int i; if(ac !=1 || zend_parse_parameters(1 TSRMLS_CC,"s",&char_bname,&char_len) ==FAILURE){ WRONG_PARAM_COUNT; } if(getSession()->nowfavmode != 1) RETURN_LONG(-1); i=getbid(char_bname,NULL); if(i >0 && ! IsFavBoard(i - 1, getSession(), -1, -1)) { addFavBoard(i - 1, getSession(), -1, -1); save_favboard(1, getSession()); }}/** * Fetch all fav boards which have given prefix into an array. * prototype: * array bbs_fav_boards(char *prefix, int yank); * * @return array of loaded fav boards on success, * FALSE on failure. * @ */PHP_FUNCTION(bbs_fav_boards){ long select; long mode; long flag = 0; int rows = 0; struct newpostdata newpost_buffer[FAVBOARDNUM]; struct newpostdata *ptr; zval **columns; zval *element; int i; int j; int brdnum; int new_return_mode; /* * getting arguments */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|l", &select, &mode, &flag) == FAILURE) { WRONG_PARAM_COUNT; } new_return_mode = (flag & 1); /* * loading boards */ /* * handle some global variables: getCurrentUser(), yank, brdnum, * * nbrd. */ /* * NOTE: getCurrentUser() SHOULD had been set in funcs.php, * * but we still check it. */ if (mode==2){ load_favboard(2, getSession()); if(select>=0 && select<favbrd_list_t) SetFav(select, getSession()); } else if(mode==3){ load_favboard(3, getSession()); if(select>=0 && select<favbrd_list_t) SetFav(select, getSession()); } if (getCurrentUser() == NULL) { RETURN_FALSE; } brdnum = 0; if ((brdnum = fav_loaddata(newpost_buffer, select, 1, FAVBOARDNUM, 1, NULL, getSession())) <= -1) { RETURN_FALSE; } /* * fill data in output array. */ /* * setup column names */ rows=brdnum; for (i = 0; i < rows; i++) { ptr = &newpost_buffer[i]; check_newpost(ptr, false); } if (new_return_mode) { if (array_init(return_value) == FAILURE) { RETURN_FALSE; } for(i=0;i<brdnum;i++) { MAKE_STD_ZVAL(element); array_init(element); ptr = &newpost_buffer[i]; if (ptr->flag == 0xffffffff) /* the item is a directory */ assign_favdir_zval(element, &(newpost_buffer[i])); else assign_board_zval(element, &(newpost_buffer[i])); zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&element, sizeof(zval*), NULL); } } else { if (array_init(return_value) == FAILURE) { RETURN_FALSE; } columns = emalloc(BOARD_COLUMNS * sizeof(zval *)); if (columns==NULL){ RETURN_FALSE; } for (i = 0; i < BOARD_COLUMNS; i++) { MAKE_STD_ZVAL(element); array_init(element); columns[i] = element; zend_hash_update(Z_ARRVAL_P(return_value), brd_col_names[i], strlen(brd_col_names[i]) + 1, (void *) &element, sizeof(zval *), NULL); } /* * fill data for each column */ for (i = 0; i < rows; i++) { ptr = &newpost_buffer[i]; for (j = 0; j < BOARD_COLUMNS; j++) { MAKE_STD_ZVAL(element); if (ptr->flag == 0xffffffff) /* the item is a directory */ bbs_make_favdir_zval(element, brd_col_names[j], ptr); else bbs_make_board_zval(element, brd_col_names[j], ptr); zend_hash_index_update(Z_ARRVAL_P(columns[j]), i, (void *) &element, sizeof(zval *), NULL); } } efree(columns); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -