/[LeafOK_CVS]/lbbs/src/section_list_display.c
ViewVC logotype

Diff of /lbbs/src/section_list_display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.57 by sysadm, Sat Oct 25 13:09:42 2025 UTC Revision 1.62 by sysadm, Sun Nov 2 15:11:47 2025 UTC
# Line 32  Line 32 
32  #include "str_process.h"  #include "str_process.h"
33  #include "user_info_display.h"  #include "user_info_display.h"
34  #include "user_priv.h"  #include "user_priv.h"
35    #include <errno.h>
36  #include <string.h>  #include <string.h>
37  #include <time.h>  #include <time.h>
38  #include <sys/param.h>  #include <sys/param.h>
39    
40  static int section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
41  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
42  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
43    
# Line 558  int section_list_display(const char *sna Line 559  int section_list_display(const char *sna
559          int page_id_cur;          int page_id_cur;
560          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
561          USER_INFO user_info;          USER_INFO user_info;
562            char user_intro[BBS_user_intro_max_len];
563    
564          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
565          if (p_section == NULL)          if (p_section == NULL)
# Line 575  int section_list_display(const char *sna Line 577  int section_list_display(const char *sna
577    
578          section_index = get_section_index(p_section);          section_index = get_section_index(p_section);
579    
580          if ((ret = section_list_rd_lock(p_section)) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
581          {          {
582                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("get_section_info(sid=%d) error\n", p_section->sid);
583                  return -2;                  return -4;
         }  
   
         strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);  
         stitle[sizeof(stitle) - 1] = '\0';  
         strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);  
         master_list[sizeof(master_list) - 1] = '\0';  
   
         if ((ret = section_list_rd_unlock(p_section)) < 0)  
         {  
                 log_error("section_list_rd_unlock(sid = 0) error\n");  
                 return -2;  
584          }          }
585    
586          if (aid == 0)          if (aid == 0)
# Line 671  int section_list_display(const char *sna Line 662  int section_list_display(const char *sna
662                  }                  }
663    
664                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
665    
666                  switch (ret)                  switch (ret)
667                  {                  {
668                  case EXIT_SECTION:                  case EXIT_SECTION:
669                            // Update current aid location
670                            if (p_articles[selected_index] != NULL)
671                            {
672                                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
673                            }
674                            else
675                            {
676                                    log_error("p_articles[selected_index=%d] is NULL when exit section [%s]\n", selected_index, sname);
677                            }
678                          return 0;                          return 0;
679                  case CHANGE_PAGE:                  case CHANGE_PAGE:
680                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
# Line 852  int section_list_display(const char *sna Line 853  int section_list_display(const char *sna
853                          // Update current topic                          // Update current topic
854                          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);
855    
                         // Update current aid location  
                         section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
856                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
857                          {                          {
858                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 953  int section_list_display(const char *sna Line 951  int section_list_display(const char *sna
951                          }                          }
952                          break;                          break;
953                  case QUERY_USER:                  case QUERY_USER:
954                          if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info)) < 0)                          if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0)
955                          {                          {
956                                  log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);                                  log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
957                                  return -2;                                  return -2;
# Line 1174  int section_list_ex_dir_display(SECTION_ Line 1172  int section_list_ex_dir_display(SECTION_
1172    
1173          return 0;          return 0;
1174  }  }
1175    
1176    int section_aid_locations_save(int uid)
1177    {
1178            char filename[FILE_PATH_LEN];
1179            FILE *fp;
1180            int i;
1181            int ret = 0;
1182    
1183            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1184    
1185            if ((fp = fopen(filename, "wb")) == NULL)
1186            {
1187                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1188                    return -1;
1189            }
1190    
1191            for (i = 0; i < p_section_list_pool->section_count; i++)
1192            {
1193                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1194                    {
1195                            log_error("fwrite(%s, sid) error\n", filename);
1196                            ret = -2;
1197                            break;
1198                    }
1199    
1200                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1201                    {
1202                            log_error("fwrite(%s, aid) error\n", filename);
1203                            ret = -2;
1204                            break;
1205                    }
1206            }
1207    
1208            if (fclose(fp) < 0)
1209            {
1210                    log_error("fclose(%s) error: %d\n", filename, errno);
1211                    ret = -1;
1212            }
1213    
1214            return ret;
1215    }
1216    
1217    int section_aid_locations_load(int uid)
1218    {
1219            char filename[FILE_PATH_LEN];
1220            FILE *fp;
1221            int i;
1222            int32_t sid;
1223            int32_t aid;
1224            SECTION_LIST *p_section;
1225            int ret = 0;
1226    
1227            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1228    
1229            if ((fp = fopen(filename, "rb")) == NULL)
1230            {
1231                    if (errno == ENOENT) // file not exist
1232                    {
1233                            return 0;
1234                    }
1235                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1236                    return -1;
1237            }
1238    
1239            while (!feof(fp))
1240            {
1241                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1242                    {
1243                            if (ferror(fp) == 0)
1244                            {
1245                                    break;
1246                            }
1247                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1248                            ret = -2;
1249                            break;
1250                    }
1251    
1252                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1253                    {
1254                            if (ferror(fp) == 0)
1255                            {
1256                                    break;
1257                            }
1258                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1259                            ret = -2;
1260                            break;
1261                    }
1262    
1263                    p_section = section_list_find_by_sid(sid);
1264                    if (p_section == NULL)
1265                    {
1266                            continue; // skip section no longer exist
1267                    }
1268    
1269                    i = get_section_index(p_section);
1270                    if (i < 0)
1271                    {
1272                            log_error("get_section_index(sid=%d) error\n", sid);
1273                            ret = -3;
1274                            break;
1275                    }
1276                    section_aid_locations[i] = aid;
1277            }
1278    
1279            if (fclose(fp) < 0)
1280            {
1281                    log_error("fclose(%s) error: %d\n", filename, errno);
1282                    ret = -1;
1283            }
1284    
1285            return ret;
1286    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1