/[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.61 by sysadm, Sun Nov 2 14:38:53 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                    // Update current aid location
667                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
668    
669                  switch (ret)                  switch (ret)
670                  {                  {
671                  case EXIT_SECTION:                  case EXIT_SECTION:
# Line 852  int section_list_display(const char *sna Line 847  int section_list_display(const char *sna
847                          // Update current topic                          // Update current topic
848                          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);
849    
                         // Update current aid location  
                         section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
850                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
851                          {                          {
852                                  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 945  int section_list_display(const char *sna
945                          }                          }
946                          break;                          break;
947                  case QUERY_USER:                  case QUERY_USER:
948                          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)
949                          {                          {
950                                  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);
951                                  return -2;                                  return -2;
# Line 1174  int section_list_ex_dir_display(SECTION_ Line 1166  int section_list_ex_dir_display(SECTION_
1166    
1167          return 0;          return 0;
1168  }  }
1169    
1170    int section_aid_locations_save(int uid)
1171    {
1172            char filename[FILE_PATH_LEN];
1173            FILE *fp;
1174            int i;
1175            int ret = 0;
1176    
1177            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1178    
1179            if ((fp = fopen(filename, "wb")) == NULL)
1180            {
1181                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1182                    return -1;
1183            }
1184    
1185            for (i = 0; i < p_section_list_pool->section_count; i++)
1186            {
1187                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1188                    {
1189                            log_error("fwrite(%s, sid) error\n", filename);
1190                            ret = -2;
1191                            break;
1192                    }
1193    
1194                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1195                    {
1196                            log_error("fwrite(%s, aid) error\n", filename);
1197                            ret = -2;
1198                            break;
1199                    }
1200            }
1201    
1202            if (fclose(fp) < 0)
1203            {
1204                    log_error("fclose(%s) error: %d\n", filename, errno);
1205                    ret = -1;
1206            }
1207    
1208            return ret;
1209    }
1210    
1211    int section_aid_locations_load(int uid)
1212    {
1213            char filename[FILE_PATH_LEN];
1214            FILE *fp;
1215            int i;
1216            int32_t sid;
1217            int32_t aid;
1218            SECTION_LIST *p_section;
1219            int ret = 0;
1220    
1221            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1222    
1223            if ((fp = fopen(filename, "rb")) == NULL)
1224            {
1225                    if (errno == ENOENT) // file not exist
1226                    {
1227                            return 0;
1228                    }
1229                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1230                    return -1;
1231            }
1232    
1233            while (!feof(fp))
1234            {
1235                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1236                    {
1237                            if (ferror(fp) == 0)
1238                            {
1239                                    break;
1240                            }
1241                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1242                            ret = -2;
1243                            break;
1244                    }
1245    
1246                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1247                    {
1248                            if (ferror(fp) == 0)
1249                            {
1250                                    break;
1251                            }
1252                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1253                            ret = -2;
1254                            break;
1255                    }
1256    
1257                    p_section = section_list_find_by_sid(sid);
1258                    if (p_section == NULL)
1259                    {
1260                            continue; // skip section no longer exist
1261                    }
1262    
1263                    i = get_section_index(p_section);
1264                    if (i < 0)
1265                    {
1266                            log_error("get_section_index(sid=%d) error\n", sid);
1267                            ret = -3;
1268                            break;
1269                    }
1270                    section_aid_locations[i] = aid;
1271            }
1272    
1273            if (fclose(fp) < 0)
1274            {
1275                    log_error("fclose(%s) error: %d\n", filename, errno);
1276                    ret = -1;
1277            }
1278    
1279            return ret;
1280    }


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

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