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

Diff of /lbbs/src/article_post.c

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

Revision 1.9 by sysadm, Sat Jun 14 11:15:46 2025 UTC Revision 1.14 by sysadm, Sun Jun 15 02:04:18 2025 UTC
# Line 63  int article_post(const SECTION_LIST *p_s Line 63  int article_post(const SECTION_LIST *p_s
63                  log_error("NULL pointer error\n");                  log_error("NULL pointer error\n");
64          }          }
65    
66            if (!checkpriv(&BBS_priv, p_section->sid, S_POST))
67            {
68                    clearscr();
69                    moveto(1, 1);
70                    prints("您没有权限在本版块发表文章\n");
71                    press_any_key();
72    
73                    return 0;
74            }
75    
76          p_article_new->title[0] = '\0';          p_article_new->title[0] = '\0';
77          title_input[0] = '\0';          title_input[0] = '\0';
78          p_article_new->transship = 0;          p_article_new->transship = 0;
# Line 243  int article_post(const SECTION_LIST *p_s Line 253  int article_post(const SECTION_LIST *p_s
253                  rs = NULL;                  rs = NULL;
254          }          }
255    
         content_f = malloc((size_t)len_content * 2 + 1);  
         if (content_f == NULL)  
         {  
                 log_error("malloc(content_f) error: OOM\n");  
                 ret = -1;  
                 goto cleanup;  
         }  
   
         sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1);  
         if (sql_content == NULL)  
         {  
                 log_error("malloc(sql_content) error: OOM\n");  
                 ret = -1;  
                 goto cleanup;  
         }  
   
256          // Begin transaction          // Begin transaction
257          if (mysql_query(db, "SET autocommit=0") != 0)          if (mysql_query(db, "SET autocommit=0") != 0)
258          {          {
# Line 275  int article_post(const SECTION_LIST *p_s Line 269  int article_post(const SECTION_LIST *p_s
269          }          }
270    
271          // Secure SQL parameters          // Secure SQL parameters
272            content_f = malloc((size_t)len_content * 2 + 1);
273            if (content_f == NULL)
274            {
275                    log_error("malloc(content_f) error: OOM\n");
276                    ret = -1;
277                    goto cleanup;
278            }
279    
280          mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname)));          mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname)));
281          mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title)));          mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title)));
282          mysql_real_escape_string(db, content_f, content, (unsigned long)len_content);          mysql_real_escape_string(db, content_f, content, (unsigned long)len_content);
283    
284            free(content);
285            content = NULL;
286    
287          // Add content          // Add content
288          snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1,          sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1);
289            if (sql_content == NULL)
290            {
291                    log_error("malloc(sql_content) error: OOM\n");
292                    ret = -1;
293                    goto cleanup;
294            }
295    
296            snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1,
297                           "INSERT INTO bbs_content(AID, content) values(0, '%s')",                           "INSERT INTO bbs_content(AID, content) values(0, '%s')",
298                           content_f);                           content_f);
299    
300          if (mysql_query(db, sql) != 0)          free(content_f);
301            content_f = NULL;
302    
303            if (mysql_query(db, sql_content) != 0)
304          {          {
305                  log_error("Add article content error: %s\n", mysql_error(db));                  log_error("Add article content error: %s\n", mysql_error(db));
306                  ret = -1;                  ret = -1;
# Line 293  int article_post(const SECTION_LIST *p_s Line 309  int article_post(const SECTION_LIST *p_s
309    
310          p_article_new->cid = (int32_t)mysql_insert_id(db);          p_article_new->cid = (int32_t)mysql_insert_id(db);
311    
312            free(sql_content);
313            sql_content = NULL;
314    
315          // Add article          // Add article
316          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
317                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "
# Line 410  int article_modify(const SECTION_LIST *p Line 429  int article_modify(const SECTION_LIST *p
429                  return 0;                  return 0;
430          }          }
431    
432            if (!checkpriv(&BBS_priv, p_section->sid, S_POST))
433            {
434                    clearscr();
435                    moveto(1, 1);
436                    prints("您没有权限在本版块发表文章\n");
437                    press_any_key();
438    
439                    return 0;
440            }
441    
442          db = db_open();          db = db_open();
443          if (db == NULL)          if (db == NULL)
444          {          {
# Line 438  int article_modify(const SECTION_LIST *p Line 467  int article_modify(const SECTION_LIST *p
467    
468          if ((row = mysql_fetch_row(rs)))          if ((row = mysql_fetch_row(rs)))
469          {          {
470                  p_editor_data = editor_data_load(row[1]);                  content = malloc(ARTICLE_CONTENT_MAX_LEN);
471                    if (content == NULL)
472                    {
473                            log_error("malloc(content) error: OOM\n");
474                            ret = -1;
475                            goto cleanup;
476                    }
477    
478                    strncpy(content, row[1], ARTICLE_CONTENT_MAX_LEN - 1);
479                    content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0';
480    
481                    // Remove control sequence
482                    len_content = ctrl_seq_filter(content);
483    
484                    p_editor_data = editor_data_load(content);
485                  if (p_editor_data == NULL)                  if (p_editor_data == NULL)
486                  {                  {
487                          log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0]));                          log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0]));
488                          ret = -3;                          ret = -3;
489                          goto cleanup;                          goto cleanup;
490                  }                  }
491    
492                    free(content);
493                    content = NULL;
494          }          }
495          mysql_free_result(rs);          mysql_free_result(rs);
496          rs = NULL;          rs = NULL;
# Line 510  int article_modify(const SECTION_LIST *p Line 556  int article_modify(const SECTION_LIST *p
556                                                          "\n--\n※ 作者已于 %s 修改本文※\n",                                                          "\n--\n※ 作者已于 %s 修改本文※\n",
557                                                          str_modify_dt);                                                          str_modify_dt);
558    
         content_f = malloc((size_t)len_content * 2 + 1);  
         if (content_f == NULL)  
         {  
                 log_error("malloc(content_f) error: OOM\n");  
                 ret = -1;  
                 goto cleanup;  
         }  
   
         sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1);  
         if (sql_content == NULL)  
         {  
                 log_error("malloc(sql_content) error: OOM\n");  
                 ret = -1;  
                 goto cleanup;  
         }  
   
559          db = db_open();          db = db_open();
560          if (db == NULL)          if (db == NULL)
561          {          {
# Line 550  int article_modify(const SECTION_LIST *p Line 580  int article_modify(const SECTION_LIST *p
580          }          }
581    
582          // Secure SQL parameters          // Secure SQL parameters
583            content_f = malloc((size_t)len_content * 2 + 1);
584            if (content_f == NULL)
585            {
586                    log_error("malloc(content_f) error: OOM\n");
587                    ret = -1;
588                    goto cleanup;
589            }
590    
591          mysql_real_escape_string(db, content_f, content, (unsigned long)len_content);          mysql_real_escape_string(db, content_f, content, (unsigned long)len_content);
592    
593            free(content);
594            content = NULL;
595    
596          // Add content          // Add content
597          snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1,          sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1);
598            if (sql_content == NULL)
599            {
600                    log_error("malloc(sql_content) error: OOM\n");
601                    ret = -1;
602                    goto cleanup;
603            }
604    
605            snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1,
606                           "INSERT INTO bbs_content(AID, content) values(%d, '%s')",                           "INSERT INTO bbs_content(AID, content) values(%d, '%s')",
607                           p_article->aid, content_f);                           p_article->aid, content_f);
608    
609          if (mysql_query(db, sql) != 0)          free(content_f);
610            content_f = NULL;
611    
612            if (mysql_query(db, sql_content) != 0)
613          {          {
614                  log_error("Add article content error: %s\n", mysql_error(db));                  log_error("Add article content error: %s\n", mysql_error(db));
615                  ret = -1;                  ret = -1;
# Line 566  int article_modify(const SECTION_LIST *p Line 618  int article_modify(const SECTION_LIST *p
618    
619          p_article_new->cid = (int32_t)mysql_insert_id(db);          p_article_new->cid = (int32_t)mysql_insert_id(db);
620    
621            free(sql_content);
622            sql_content = NULL;
623    
624          // Update article          // Update article
625          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
626                           "UPDATE bbs SET CID = %d, length = %ld WHERE AID = %d",                           "UPDATE bbs SET CID = %d, length = %ld WHERE AID = %d",
# Line 613  int article_modify(const SECTION_LIST *p Line 668  int article_modify(const SECTION_LIST *p
668          ret = 1; // Success          ret = 1; // Success
669    
670  cleanup:  cleanup:
671            mysql_free_result(rs);
672          mysql_close(db);          mysql_close(db);
673    
674          // Cleanup buffers          // Cleanup buffers
# Line 649  int article_reply(const SECTION_LIST *p_ Line 705  int article_reply(const SECTION_LIST *p_
705          long quote_content_lines;          long quote_content_lines;
706          long i;          long i;
707          long ret = 0;          long ret = 0;
708            int topic_locked = 0;
709    
710          if (p_section == NULL || p_article == NULL)          if (p_section == NULL || p_article == NULL)
711          {          {
712                  log_error("NULL pointer error\n");                  log_error("NULL pointer error\n");
713          }          }
714    
715          if (p_article->lock) // Reply is not allowed          if (!checkpriv(&BBS_priv, p_section->sid, S_POST))
716          {          {
717                  clearscr();                  clearscr();
718                  moveto(1, 1);                  moveto(1, 1);
719                  prints("该文章谢绝回复");                  prints("您没有权限在本版块发表文章\n");
720                  press_any_key();                  press_any_key();
721    
722                  return 0;                  return 0;
# Line 678  int article_reply(const SECTION_LIST *p_ Line 735  int article_reply(const SECTION_LIST *p_
735          }          }
736    
737          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
738                             "SELECT `lock` FROM bbs WHERE AID = %d",
739                             (p_article->tid == 0 ? p_article->aid : p_article->tid));
740    
741            if (mysql_query(db, sql) != 0)
742            {
743                    log_error("Query article status error: %s\n", mysql_error(db));
744                    return -2;
745            }
746            if ((rs = mysql_store_result(db)) == NULL)
747            {
748                    log_error("Get article status data failed\n");
749                    return -2;
750            }
751    
752            if ((row = mysql_fetch_row(rs)))
753            {
754                    if (atoi(row[0]) != 0)
755                    {
756                            topic_locked = 1;
757                    }
758            }
759            mysql_free_result(rs);
760            rs = NULL;
761    
762            if (topic_locked) // Reply is not allowed
763            {
764                    clearscr();
765                    moveto(1, 1);
766                    prints("该主题谢绝回复");
767                    press_any_key();
768    
769                    goto cleanup;
770            }
771    
772            snprintf(sql, sizeof(sql),
773                           "SELECT bbs_content.CID, bbs_content.content "                           "SELECT bbs_content.CID, bbs_content.content "
774                           "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "                           "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "
775                           "WHERE bbs.AID = %d",                           "WHERE bbs.AID = %d",
# Line 921  int article_reply(const SECTION_LIST *p_ Line 1013  int article_reply(const SECTION_LIST *p_
1013                  rs = NULL;                  rs = NULL;
1014          }          }
1015    
         content_f = malloc((size_t)len_content * 2 + 1);  
         if (content_f == NULL)  
         {  
                 log_error("malloc(content_f) error: OOM\n");  
                 ret = -1;  
                 goto cleanup;  
         }  
   
         sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1);  
         if (sql_content == NULL)  
         {  
                 log_error("malloc(sql_content) error: OOM\n");  
                 ret = -1;  
                 goto cleanup;  
         }  
   
1016          // Begin transaction          // Begin transaction
1017          if (mysql_query(db, "SET autocommit=0") != 0)          if (mysql_query(db, "SET autocommit=0") != 0)
1018          {          {
# Line 953  int article_reply(const SECTION_LIST *p_ Line 1029  int article_reply(const SECTION_LIST *p_
1029          }          }
1030    
1031          // Secure SQL parameters          // Secure SQL parameters
1032            content_f = malloc((size_t)len_content * 2 + 1);
1033            if (content_f == NULL)
1034            {
1035                    log_error("malloc(content_f) error: OOM\n");
1036                    ret = -1;
1037                    goto cleanup;
1038            }
1039    
1040          mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname)));          mysql_real_escape_string(db, nickname_f, BBS_nickname, (unsigned long)strnlen(BBS_nickname, sizeof(BBS_nickname)));
1041          mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title)));          mysql_real_escape_string(db, title_f, p_article_new->title, strnlen(p_article_new->title, sizeof(p_article_new->title)));
1042          mysql_real_escape_string(db, content_f, content, (unsigned long)len_content);          mysql_real_escape_string(db, content_f, content, (unsigned long)len_content);
1043    
1044            free(content);
1045            content = NULL;
1046    
1047          // Add content          // Add content
1048          snprintf(sql, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1,          sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1);
1049            if (sql_content == NULL)
1050            {
1051                    log_error("malloc(sql_content) error: OOM\n");
1052                    ret = -1;
1053                    goto cleanup;
1054            }
1055    
1056            snprintf(sql_content, SQL_BUFFER_LEN + (size_t)len_content * 2 + 1,
1057                           "INSERT INTO bbs_content(AID, content) values(0, '%s')",                           "INSERT INTO bbs_content(AID, content) values(0, '%s')",
1058                           content_f);                           content_f);
1059    
1060          if (mysql_query(db, sql) != 0)          free(content_f);
1061            content_f = NULL;
1062    
1063            if (mysql_query(db, sql_content) != 0)
1064          {          {
1065                  log_error("Add article content error: %s\n", mysql_error(db));                  log_error("Add article content error: %s\n", mysql_error(db));
1066                  ret = -1;                  ret = -1;
# Line 971  int article_reply(const SECTION_LIST *p_ Line 1069  int article_reply(const SECTION_LIST *p_
1069    
1070          p_article_new->cid = (int32_t)mysql_insert_id(db);          p_article_new->cid = (int32_t)mysql_insert_id(db);
1071    
1072            free(sql_content);
1073            sql_content = NULL;
1074    
1075          // Add article          // Add article
1076          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
1077                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "
1078                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "
1079                           "VALUES(%d, 0, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', 1, %d, NOW(), 1, %ld)",                           "VALUES(%d, %d, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', 1, %d, NOW(), 1, %ld)",
1080                           p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f,                           p_section->sid, (p_article->tid == 0 ? p_article->aid : p_article->tid),
1081                             BBS_priv.uid, BBS_username, nickname_f, title_f,
1082                           p_article_new->cid, hostaddr_client, BBS_user_exp, len_content);                           p_article_new->cid, hostaddr_client, BBS_user_exp, len_content);
1083    
1084          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
# Line 992  int article_reply(const SECTION_LIST *p_ Line 1094  int article_reply(const SECTION_LIST *p_
1094          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
1095                           "UPDATE bbs SET reply_count = reply_count + 1, "                           "UPDATE bbs SET reply_count = reply_count + 1, "
1096                           "last_reply_dt = NOW(), last_reply_UID=%d, last_reply_username = '%s', "                           "last_reply_dt = NOW(), last_reply_UID=%d, last_reply_username = '%s', "
1097                           "last_reply_nickname = '%s' WHERE Aid = %d",                           "last_reply_nickname = '%s' WHERE AID = %d",
1098                           BBS_priv.uid, BBS_username, nickname_f, p_article->aid);                           BBS_priv.uid, BBS_username, nickname_f,
1099                             (p_article->tid == 0 ? p_article->aid : p_article->tid));
1100    
1101            if (mysql_query(db, sql) != 0)
1102            {
1103                    log_error("Update topic article error: %s\n", mysql_error(db));
1104                    ret = -1;
1105                    goto cleanup;
1106            }
1107    
1108          // Link content to article          // Link content to article
1109          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),


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

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