| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#define _POSIX_C_SOURCE 200809L |
|
|
|
|
|
#include "section_list_display.h" |
|
|
#include "section_list_loader.h" |
|
| 17 |
#include "article_cache.h" |
#include "article_cache.h" |
| 18 |
#include "article_post.h" |
#include "article_post.h" |
| 19 |
|
#include "article_view_log.h" |
| 20 |
#include "article_del.h" |
#include "article_del.h" |
| 21 |
#include "common.h" |
#include "common.h" |
| 22 |
#include "io.h" |
#include "io.h" |
|
#include "screen.h" |
|
| 23 |
#include "log.h" |
#include "log.h" |
| 24 |
#include "user_priv.h" |
#include "login.h" |
| 25 |
#include "article_view_log.h" |
#include "section_list_display.h" |
| 26 |
|
#include "section_list_loader.h" |
| 27 |
|
#include "screen.h" |
| 28 |
#include "str_process.h" |
#include "str_process.h" |
| 29 |
|
#include "user_priv.h" |
| 30 |
#include <string.h> |
#include <string.h> |
| 31 |
#include <time.h> |
#include <time.h> |
| 32 |
#include <sys/param.h> |
#include <sys/param.h> |
| 39 |
EXIT_SECTION = 0, |
EXIT_SECTION = 0, |
| 40 |
VIEW_ARTICLE = 1, |
VIEW_ARTICLE = 1, |
| 41 |
CHANGE_PAGE = 2, |
CHANGE_PAGE = 2, |
| 42 |
REFRESH_SCREEN = 3, |
SHOW_HELP = 3, |
| 43 |
CHANGE_NAME_DISPLAY = 4, |
CHANGE_NAME_DISPLAY = 4, |
| 44 |
POST_ARTICLE = 5, |
POST_ARTICLE = 5, |
| 45 |
EDIT_ARTICLE = 6, |
EDIT_ARTICLE = 6, |
| 46 |
DELETE_ARTICLE = 7, |
DELETE_ARTICLE = 7, |
| 47 |
SHOW_HELP = 8, |
FIRST_TOPIC_ARTICLE = 8, |
| 48 |
|
LAST_TOPIC_ARTICLE = 9, |
| 49 |
}; |
}; |
| 50 |
|
|
| 51 |
static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname) |
static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname) |
| 165 |
int old_page_id = *p_page_id; |
int old_page_id = *p_page_id; |
| 166 |
int old_selected_index = *p_selected_index; |
int old_selected_index = *p_selected_index; |
| 167 |
int ch; |
int ch; |
| 168 |
|
time_t last_refresh_tm = time(NULL); |
|
BBS_last_access_tm = time(0); |
|
| 169 |
|
|
| 170 |
if (item_count > 0 && *p_selected_index >= 0) |
if (item_count > 0 && *p_selected_index >= 0) |
| 171 |
{ |
{ |
| 180 |
|
|
| 181 |
switch (ch) |
switch (ch) |
| 182 |
{ |
{ |
|
case KEY_NULL: // broken pipe |
|
| 183 |
case KEY_ESC: |
case KEY_ESC: |
| 184 |
case KEY_LEFT: |
case KEY_LEFT: |
| 185 |
|
BBS_last_access_tm = time(NULL); |
| 186 |
|
case KEY_NULL: // broken pipe |
| 187 |
return EXIT_SECTION; // exit section |
return EXIT_SECTION; // exit section |
| 188 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 189 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 190 |
{ |
{ |
| 191 |
return EXIT_SECTION; // exit section |
return EXIT_SECTION; // exit section |
| 192 |
} |
} |
| 193 |
continue; |
continue; |
| 194 |
case 'n': |
case 'n': |
| 195 |
|
BBS_last_access_tm = time(NULL); |
| 196 |
return CHANGE_NAME_DISPLAY; |
return CHANGE_NAME_DISPLAY; |
| 197 |
case CR: |
case CR: |
| 198 |
igetch_reset(); |
igetch_reset(); |
| 200 |
case KEY_RIGHT: |
case KEY_RIGHT: |
| 201 |
if (item_count > 0) |
if (item_count > 0) |
| 202 |
{ |
{ |
| 203 |
|
BBS_last_access_tm = time(NULL); |
| 204 |
return VIEW_ARTICLE; |
return VIEW_ARTICLE; |
| 205 |
} |
} |
| 206 |
break; |
break; |
| 261 |
(*p_selected_index)++; |
(*p_selected_index)++; |
| 262 |
} |
} |
| 263 |
break; |
break; |
| 264 |
|
case '=': |
| 265 |
|
return FIRST_TOPIC_ARTICLE; |
| 266 |
|
case '\\': |
| 267 |
|
return LAST_TOPIC_ARTICLE; |
| 268 |
case 'h': |
case 'h': |
| 269 |
return SHOW_HELP; |
return SHOW_HELP; |
| 270 |
default: |
default: |
| 292 |
old_selected_index = *p_selected_index; |
old_selected_index = *p_selected_index; |
| 293 |
} |
} |
| 294 |
|
|
| 295 |
BBS_last_access_tm = time(0); |
BBS_last_access_tm = time(NULL); |
| 296 |
|
if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval) |
| 297 |
|
{ |
| 298 |
|
return CHANGE_PAGE; // force section list refresh |
| 299 |
|
} |
| 300 |
} |
} |
| 301 |
|
|
| 302 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 328 |
break; |
break; |
| 329 |
case 'r': // Reply article |
case 'r': // Reply article |
| 330 |
return 1; |
return 1; |
| 331 |
|
case '=': // First topic article |
| 332 |
|
return 1; |
| 333 |
|
case '\\': // Last topic article |
| 334 |
|
return 1; |
| 335 |
case KEY_UP: |
case KEY_UP: |
| 336 |
case KEY_PGUP: |
case KEY_PGUP: |
| 337 |
case KEY_HOME: |
case KEY_HOME: |
| 407 |
int loop; |
int loop; |
| 408 |
int direction; |
int direction; |
| 409 |
ARTICLE article_new; |
ARTICLE article_new; |
| 410 |
|
int page_id_cur; |
| 411 |
|
|
| 412 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 413 |
if (p_section == NULL) |
if (p_section == NULL) |
| 467 |
show_bottom(page_info_str); |
show_bottom(page_info_str); |
| 468 |
iflush(); |
iflush(); |
| 469 |
|
|
| 470 |
|
if (user_online_update(sname) < 0) |
| 471 |
|
{ |
| 472 |
|
log_error("user_online_update(%s) error\n", sname); |
| 473 |
|
} |
| 474 |
|
|
| 475 |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
| 476 |
switch (ret) |
switch (ret) |
| 477 |
{ |
{ |
| 504 |
break; |
break; |
| 505 |
} |
} |
| 506 |
|
|
| 507 |
|
if (user_online_update("VIEW_ARTICLE") < 0) |
| 508 |
|
{ |
| 509 |
|
log_error("user_online_update(VIEW_ARTICLE) error\n"); |
| 510 |
|
} |
| 511 |
|
|
| 512 |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, |
| 513 |
display_article_key_handler, DATA_READ_HELP); |
display_article_key_handler, DATA_READ_HELP); |
| 514 |
|
|
| 591 |
case KEY_PGUP: |
case KEY_PGUP: |
| 592 |
case KEY_PGDN: |
case KEY_PGDN: |
| 593 |
direction = (ret == KEY_PGUP ? -1 : 1); |
direction = (ret == KEY_PGUP ? -1 : 1); |
| 594 |
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, &page_id, &selected_index, &page_count); |
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, 1, |
| 595 |
|
&page_id, &selected_index, &article_count); |
| 596 |
if (ret < 0) |
if (ret < 0) |
| 597 |
{ |
{ |
| 598 |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d) error\n", |
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n", |
| 599 |
p_section->sid, p_articles[selected_index]->aid, direction); |
p_section->sid, p_articles[selected_index]->aid, direction); |
| 600 |
return -3; |
return -3; |
| 601 |
} |
} |
| 602 |
else if (ret > 0) |
else if (ret > 0) // found |
| 603 |
{ |
{ |
| 604 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 605 |
if (ret < 0) |
if (ret < 0) |
| 611 |
} |
} |
| 612 |
break; |
break; |
| 613 |
case 'r': // Reply article |
case 'r': // Reply article |
| 614 |
|
if (user_online_update("REPLY_ARTICLE") < 0) |
| 615 |
|
{ |
| 616 |
|
log_error("user_online_update(REPLY_ARTICLE) error\n"); |
| 617 |
|
} |
| 618 |
|
|
| 619 |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
| 620 |
{ |
{ |
| 621 |
log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid); |
log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid); |
| 622 |
} |
} |
| 623 |
loop = 1; |
loop = 1; |
| 624 |
break; |
break; |
| 625 |
|
case '=': // First topic article |
| 626 |
|
case '\\': // Last topic article |
| 627 |
|
page_id_cur = page_id; |
| 628 |
|
direction = (ret == '=' ? -1 : 1); |
| 629 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section, |
| 630 |
|
&page_id, &selected_index, &article_count); |
| 631 |
|
if (ret < 0) |
| 632 |
|
{ |
| 633 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
| 634 |
|
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 635 |
|
return -3; |
| 636 |
|
} |
| 637 |
|
else if (ret > 0) // found |
| 638 |
|
{ |
| 639 |
|
if (page_id != page_id_cur) // page changed |
| 640 |
|
{ |
| 641 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 642 |
|
if (ret < 0) |
| 643 |
|
{ |
| 644 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 645 |
|
return -3; |
| 646 |
|
} |
| 647 |
|
} |
| 648 |
|
loop = 1; |
| 649 |
|
} |
| 650 |
|
break; |
| 651 |
} |
} |
| 652 |
} while (loop); |
} while (loop); |
| 653 |
|
|
| 654 |
// Update current topic |
// Update current topic |
| 655 |
section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
|
case REFRESH_SCREEN: |
|
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
|
|
{ |
|
|
log_error("section_list_draw_screen() error\n"); |
|
|
return -2; |
|
|
} |
|
|
break; |
|
| 656 |
case CHANGE_NAME_DISPLAY: |
case CHANGE_NAME_DISPLAY: |
| 657 |
display_nickname = !display_nickname; |
display_nickname = !display_nickname; |
| 658 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 662 |
} |
} |
| 663 |
break; |
break; |
| 664 |
case POST_ARTICLE: |
case POST_ARTICLE: |
| 665 |
ret = article_post(p_section, &article_new); |
if (user_online_update("POST_ARTICLE") < 0) |
| 666 |
if (ret < 0) |
{ |
| 667 |
|
log_error("user_online_update(POST_ARTICLE) error\n"); |
| 668 |
|
} |
| 669 |
|
|
| 670 |
|
if ((ret = article_post(p_section, &article_new)) < 0) |
| 671 |
{ |
{ |
| 672 |
log_error("article_post(sid=%d) error\n", p_section->sid); |
log_error("article_post(sid=%d) error\n", p_section->sid); |
| 673 |
} |
} |
| 692 |
{ |
{ |
| 693 |
break; // No permission |
break; // No permission |
| 694 |
} |
} |
| 695 |
|
|
| 696 |
|
if (user_online_update("EDIT_ARTICLE") < 0) |
| 697 |
|
{ |
| 698 |
|
log_error("user_online_update() error\n"); |
| 699 |
|
} |
| 700 |
|
|
| 701 |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 702 |
{ |
{ |
| 703 |
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
| 714 |
{ |
{ |
| 715 |
break; // No permission |
break; // No permission |
| 716 |
} |
} |
| 717 |
if (article_del(p_section, p_articles[selected_index]) < 0) |
if ((ret = article_del(p_section, p_articles[selected_index])) < 0) |
| 718 |
{ |
{ |
| 719 |
log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid); |
| 720 |
} |
} |
| 721 |
|
else if (ret > 0) // Article deleted |
| 722 |
|
{ |
| 723 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 724 |
|
if (ret < 0) |
| 725 |
|
{ |
| 726 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 727 |
|
return -3; |
| 728 |
|
} |
| 729 |
|
} |
| 730 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 731 |
{ |
{ |
| 732 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 733 |
return -2; |
return -2; |
| 734 |
} |
} |
| 735 |
break; |
break; |
| 736 |
|
case FIRST_TOPIC_ARTICLE: |
| 737 |
|
case LAST_TOPIC_ARTICLE: |
| 738 |
|
page_id_cur = page_id; |
| 739 |
|
direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1); |
| 740 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section, |
| 741 |
|
&page_id, &selected_index, &article_count); |
| 742 |
|
if (ret < 0) |
| 743 |
|
{ |
| 744 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
| 745 |
|
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 746 |
|
return -3; |
| 747 |
|
} |
| 748 |
|
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 749 |
|
{ |
| 750 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 751 |
|
if (ret < 0) |
| 752 |
|
{ |
| 753 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 754 |
|
return -3; |
| 755 |
|
} |
| 756 |
|
} |
| 757 |
|
break; |
| 758 |
case SHOW_HELP: |
case SHOW_HELP: |
| 759 |
// Display help information |
// Display help information |
| 760 |
display_file(DATA_READ_HELP, 1); |
display_file(DATA_READ_HELP, 1); |