| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#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> |
| 31 |
#include <time.h> |
#include <time.h> |
| 32 |
#include <sys/param.h> |
#include <sys/param.h> |
|
#define _POSIX_C_SOURCE 200809L |
|
|
#include <string.h> |
|
| 33 |
|
|
| 34 |
static int section_topic_view_mode = 0; |
static int section_topic_view_mode = 0; |
| 35 |
static int section_topic_view_tid = -1; |
static int section_topic_view_tid = -1; |
| 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) |
| 81 |
} |
} |
| 82 |
} |
} |
| 83 |
|
|
|
article_flag = (is_viewed ? ' ' : 'N'); |
|
|
|
|
| 84 |
if (p_articles[i]->excerption) |
if (p_articles[i]->excerption) |
| 85 |
{ |
{ |
| 86 |
article_flag = (is_viewed ? 'm' : 'M'); |
article_flag = (is_viewed ? 'm' : 'M'); |
| 89 |
{ |
{ |
| 90 |
article_flag = 'x'; |
article_flag = 'x'; |
| 91 |
} |
} |
| 92 |
|
else |
| 93 |
|
{ |
| 94 |
|
article_flag = (is_viewed ? ' ' : 'N'); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
localtime_r(&p_articles[i]->sub_dt, &tm_sub); |
localtime_r(&p_articles[i]->sub_dt, &tm_sub); |
| 98 |
if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365) |
if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365) |
| 116 |
|
|
| 117 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 118 |
prints(" %s%7d\033[m %c %s%*s %s %s%s\033[m", |
prints(" %s%7d\033[m %c %s%*s %s %s%s\033[m", |
| 119 |
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
(p_articles[i]->ontop |
| 120 |
|
? "\033[47;30m" |
| 121 |
|
: (p_articles[i]->aid == section_topic_view_tid |
| 122 |
|
? "\033[1;33m" |
| 123 |
|
: (p_articles[i]->tid == section_topic_view_tid |
| 124 |
|
? "\033[1;36m" |
| 125 |
|
: ""))), |
| 126 |
p_articles[i]->aid, |
p_articles[i]->aid, |
| 127 |
article_flag, |
article_flag, |
| 128 |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
| 130 |
: BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))), |
: BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))), |
| 131 |
"", |
"", |
| 132 |
str_time, |
str_time, |
| 133 |
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
(p_articles[i]->aid == section_topic_view_tid |
| 134 |
|
? "\033[1;33m" |
| 135 |
|
: (p_articles[i]->tid == section_topic_view_tid |
| 136 |
|
? "\033[1;36m" |
| 137 |
|
: "")), |
| 138 |
title_f); |
title_f); |
| 139 |
} |
} |
| 140 |
|
|
| 177 |
int old_page_id = *p_page_id; |
int old_page_id = *p_page_id; |
| 178 |
int old_selected_index = *p_selected_index; |
int old_selected_index = *p_selected_index; |
| 179 |
int ch; |
int ch; |
| 180 |
|
time_t last_refresh_tm = time(NULL); |
|
BBS_last_access_tm = time(0); |
|
| 181 |
|
|
| 182 |
if (item_count > 0 && *p_selected_index >= 0) |
if (item_count > 0 && *p_selected_index >= 0) |
| 183 |
{ |
{ |
| 192 |
|
|
| 193 |
switch (ch) |
switch (ch) |
| 194 |
{ |
{ |
|
case KEY_NULL: // broken pipe |
|
| 195 |
case KEY_ESC: |
case KEY_ESC: |
| 196 |
case KEY_LEFT: |
case KEY_LEFT: |
| 197 |
|
BBS_last_access_tm = time(NULL); |
| 198 |
|
case KEY_NULL: // broken pipe |
| 199 |
return EXIT_SECTION; // exit section |
return EXIT_SECTION; // exit section |
| 200 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 201 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 202 |
{ |
{ |
| 203 |
return EXIT_SECTION; // exit section |
return EXIT_SECTION; // exit section |
| 204 |
} |
} |
| 205 |
continue; |
continue; |
| 206 |
case 'n': |
case 'n': |
| 207 |
|
BBS_last_access_tm = time(NULL); |
| 208 |
return CHANGE_NAME_DISPLAY; |
return CHANGE_NAME_DISPLAY; |
| 209 |
case CR: |
case CR: |
| 210 |
igetch_reset(); |
igetch_reset(); |
| 212 |
case KEY_RIGHT: |
case KEY_RIGHT: |
| 213 |
if (item_count > 0) |
if (item_count > 0) |
| 214 |
{ |
{ |
| 215 |
|
BBS_last_access_tm = time(NULL); |
| 216 |
return VIEW_ARTICLE; |
return VIEW_ARTICLE; |
| 217 |
} |
} |
| 218 |
break; |
break; |
| 273 |
(*p_selected_index)++; |
(*p_selected_index)++; |
| 274 |
} |
} |
| 275 |
break; |
break; |
| 276 |
|
case '=': |
| 277 |
|
return FIRST_TOPIC_ARTICLE; |
| 278 |
|
case '\\': |
| 279 |
|
return LAST_TOPIC_ARTICLE; |
| 280 |
case 'h': |
case 'h': |
| 281 |
return SHOW_HELP; |
return SHOW_HELP; |
| 282 |
default: |
default: |
| 304 |
old_selected_index = *p_selected_index; |
old_selected_index = *p_selected_index; |
| 305 |
} |
} |
| 306 |
|
|
| 307 |
BBS_last_access_tm = time(0); |
BBS_last_access_tm = time(NULL); |
| 308 |
|
if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval) |
| 309 |
|
{ |
| 310 |
|
return CHANGE_PAGE; // force section list refresh |
| 311 |
|
} |
| 312 |
} |
} |
| 313 |
|
|
| 314 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 340 |
break; |
break; |
| 341 |
case 'r': // Reply article |
case 'r': // Reply article |
| 342 |
return 1; |
return 1; |
| 343 |
|
case '=': // First topic article |
| 344 |
|
return 1; |
| 345 |
|
case '\\': // Last topic article |
| 346 |
|
return 1; |
| 347 |
case KEY_UP: |
case KEY_UP: |
| 348 |
case KEY_PGUP: |
case KEY_PGUP: |
| 349 |
case KEY_HOME: |
case KEY_HOME: |
| 419 |
int loop; |
int loop; |
| 420 |
int direction; |
int direction; |
| 421 |
ARTICLE article_new; |
ARTICLE article_new; |
| 422 |
|
int page_id_cur; |
| 423 |
|
|
| 424 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 425 |
if (p_section == NULL) |
if (p_section == NULL) |
| 479 |
show_bottom(page_info_str); |
show_bottom(page_info_str); |
| 480 |
iflush(); |
iflush(); |
| 481 |
|
|
| 482 |
|
if (user_online_update(sname) < 0) |
| 483 |
|
{ |
| 484 |
|
log_error("user_online_update(%s) error\n", sname); |
| 485 |
|
} |
| 486 |
|
|
| 487 |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
| 488 |
switch (ret) |
switch (ret) |
| 489 |
{ |
{ |
| 516 |
break; |
break; |
| 517 |
} |
} |
| 518 |
|
|
| 519 |
|
if (user_online_update("VIEW_ARTICLE") < 0) |
| 520 |
|
{ |
| 521 |
|
log_error("user_online_update(VIEW_ARTICLE) error\n"); |
| 522 |
|
} |
| 523 |
|
|
| 524 |
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, |
| 525 |
display_article_key_handler, DATA_READ_HELP); |
display_article_key_handler, DATA_READ_HELP); |
| 526 |
|
|
| 603 |
case KEY_PGUP: |
case KEY_PGUP: |
| 604 |
case KEY_PGDN: |
case KEY_PGDN: |
| 605 |
direction = (ret == KEY_PGUP ? -1 : 1); |
direction = (ret == KEY_PGUP ? -1 : 1); |
| 606 |
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, |
| 607 |
|
&page_id, &selected_index, &article_count); |
| 608 |
if (ret < 0) |
if (ret < 0) |
| 609 |
{ |
{ |
| 610 |
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", |
| 611 |
p_section->sid, p_articles[selected_index]->aid, direction); |
p_section->sid, p_articles[selected_index]->aid, direction); |
| 612 |
return -3; |
return -3; |
| 613 |
} |
} |
| 614 |
else if (ret > 0) |
else if (ret > 0) // found |
| 615 |
{ |
{ |
| 616 |
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); |
| 617 |
if (ret < 0) |
if (ret < 0) |
| 623 |
} |
} |
| 624 |
break; |
break; |
| 625 |
case 'r': // Reply article |
case 'r': // Reply article |
| 626 |
|
if (user_online_update("REPLY_ARTICLE") < 0) |
| 627 |
|
{ |
| 628 |
|
log_error("user_online_update(REPLY_ARTICLE) error\n"); |
| 629 |
|
} |
| 630 |
|
|
| 631 |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
| 632 |
{ |
{ |
| 633 |
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); |
| 634 |
} |
} |
| 635 |
loop = 1; |
loop = 1; |
| 636 |
break; |
break; |
| 637 |
|
case '=': // First topic article |
| 638 |
|
case '\\': // Last topic article |
| 639 |
|
page_id_cur = page_id; |
| 640 |
|
direction = (ret == '=' ? -1 : 1); |
| 641 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section, |
| 642 |
|
&page_id, &selected_index, &article_count); |
| 643 |
|
if (ret < 0) |
| 644 |
|
{ |
| 645 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
| 646 |
|
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 647 |
|
return -3; |
| 648 |
|
} |
| 649 |
|
else if (ret > 0) // found |
| 650 |
|
{ |
| 651 |
|
if (page_id != page_id_cur) // page changed |
| 652 |
|
{ |
| 653 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 654 |
|
if (ret < 0) |
| 655 |
|
{ |
| 656 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 657 |
|
return -3; |
| 658 |
|
} |
| 659 |
|
} |
| 660 |
|
loop = 1; |
| 661 |
|
} |
| 662 |
|
break; |
| 663 |
} |
} |
| 664 |
} while (loop); |
} while (loop); |
| 665 |
|
|
| 666 |
// Update current topic |
// Update current topic |
| 667 |
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); |
| 668 |
case REFRESH_SCREEN: |
|
| 669 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 670 |
{ |
{ |
| 671 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 681 |
} |
} |
| 682 |
break; |
break; |
| 683 |
case POST_ARTICLE: |
case POST_ARTICLE: |
| 684 |
ret = article_post(p_section, &article_new); |
if (user_online_update("POST_ARTICLE") < 0) |
| 685 |
if (ret < 0) |
{ |
| 686 |
|
log_error("user_online_update(POST_ARTICLE) error\n"); |
| 687 |
|
} |
| 688 |
|
|
| 689 |
|
if ((ret = article_post(p_section, &article_new)) < 0) |
| 690 |
{ |
{ |
| 691 |
log_error("article_post(sid=%d) error\n", p_section->sid); |
log_error("article_post(sid=%d) error\n", p_section->sid); |
| 692 |
} |
} |
| 711 |
{ |
{ |
| 712 |
break; // No permission |
break; // No permission |
| 713 |
} |
} |
| 714 |
|
|
| 715 |
|
if (user_online_update("EDIT_ARTICLE") < 0) |
| 716 |
|
{ |
| 717 |
|
log_error("user_online_update() error\n"); |
| 718 |
|
} |
| 719 |
|
|
| 720 |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 721 |
{ |
{ |
| 722 |
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); |
| 733 |
{ |
{ |
| 734 |
break; // No permission |
break; // No permission |
| 735 |
} |
} |
| 736 |
if (article_del(p_section, p_articles[selected_index]) < 0) |
if ((ret = article_del(p_section, p_articles[selected_index])) < 0) |
| 737 |
{ |
{ |
| 738 |
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); |
| 739 |
} |
} |
| 740 |
|
else if (ret > 0) // Article deleted |
| 741 |
|
{ |
| 742 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 743 |
|
if (ret < 0) |
| 744 |
|
{ |
| 745 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 746 |
|
return -3; |
| 747 |
|
} |
| 748 |
|
} |
| 749 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 750 |
{ |
{ |
| 751 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 752 |
return -2; |
return -2; |
| 753 |
} |
} |
| 754 |
break; |
break; |
| 755 |
|
case FIRST_TOPIC_ARTICLE: |
| 756 |
|
case LAST_TOPIC_ARTICLE: |
| 757 |
|
page_id_cur = page_id; |
| 758 |
|
direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1); |
| 759 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section, |
| 760 |
|
&page_id, &selected_index, &article_count); |
| 761 |
|
if (ret < 0) |
| 762 |
|
{ |
| 763 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", |
| 764 |
|
p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); |
| 765 |
|
return -3; |
| 766 |
|
} |
| 767 |
|
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 768 |
|
{ |
| 769 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 770 |
|
if (ret < 0) |
| 771 |
|
{ |
| 772 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 773 |
|
return -3; |
| 774 |
|
} |
| 775 |
|
} |
| 776 |
|
break; |
| 777 |
case SHOW_HELP: |
case SHOW_HELP: |
| 778 |
// Display help information |
// Display help information |
| 779 |
display_file(DATA_READ_HELP, 1); |
display_file(DATA_READ_HELP, 1); |