/[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.14 by sysadm, Sun Jun 15 02:04:18 2025 UTC Revision 1.22 by sysadm, Sat Jun 21 02:15:18 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
 #define _POSIX_C_SOURCE 200809L  
   
 #include "article_post.h"  
17  #include "article_cache.h"  #include "article_cache.h"
18  #include "editor.h"  #include "article_post.h"
 #include "screen.h"  
19  #include "bbs.h"  #include "bbs.h"
20  #include "log.h"  #include "database.h"
21    #include "editor.h"
22  #include "io.h"  #include "io.h"
23    #include "log.h"
24  #include "lml.h"  #include "lml.h"
25  #include "database.h"  #include "screen.h"
26  #include "user_priv.h"  #include "user_priv.h"
27  #include <ctype.h>  #include <ctype.h>
28  #include <string.h>  #include <string.h>
# Line 81  int article_post(const SECTION_LIST *p_s Line 79  int article_post(const SECTION_LIST *p_s
79          if (p_editor_data == NULL)          if (p_editor_data == NULL)
80          {          {
81                  log_error("editor_data_load() error\n");                  log_error("editor_data_load() error\n");
82                  return -2;                  ret = -1;
83                    goto cleanup;
84          }          }
85    
86          // Set title and sign          // Set title and sign
# Line 109  int article_post(const SECTION_LIST *p_s Line 108  int article_post(const SECTION_LIST *p_s
108                  {                  {
109                          switch (toupper(ch))                          switch (toupper(ch))
110                          {                          {
111                            case KEY_NULL:
112                            case KEY_TIMEOUT:
113                                    goto cleanup;
114                          case CR:                          case CR:
115                                  igetch_reset();                                  igetch_reset();
116                                  break;                                  break;
# Line 172  int article_post(const SECTION_LIST *p_s Line 174  int article_post(const SECTION_LIST *p_s
174                          {                          {
175                                  switch (toupper(ch))                                  switch (toupper(ch))
176                                  {                                  {
177                                    case KEY_NULL:
178                                    case KEY_TIMEOUT:
179                                            goto cleanup;
180                                  case CR:                                  case CR:
181                                          igetch_reset();                                          igetch_reset();
182                                  case 'S':                                  case 'S':
# Line 200  int article_post(const SECTION_LIST *p_s Line 205  int article_post(const SECTION_LIST *p_s
205                  }                  }
206          }          }
207    
208            if (SYS_server_exit) // Do not save data on shutdown
209            {
210                    goto cleanup;
211            }
212    
213          content = malloc(ARTICLE_CONTENT_MAX_LEN);          content = malloc(ARTICLE_CONTENT_MAX_LEN);
214          if (content == NULL)          if (content == NULL)
215          {          {
# Line 212  int article_post(const SECTION_LIST *p_s Line 222  int article_post(const SECTION_LIST *p_s
222          if (len_content < 0)          if (len_content < 0)
223          {          {
224                  log_error("editor_data_save() error\n");                  log_error("editor_data_save() error\n");
225                  ret = -2;                  ret = -1;
226                  goto cleanup;                  goto cleanup;
227          }          }
228    
# Line 377  int article_post(const SECTION_LIST *p_s Line 387  int article_post(const SECTION_LIST *p_s
387                  goto cleanup;                  goto cleanup;
388          }          }
389    
390            mysql_close(db);
391            db = NULL;
392    
393          clearscr();          clearscr();
394          moveto(1, 1);          moveto(1, 1);
395          prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval);          prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval);
# Line 429  int article_modify(const SECTION_LIST *p Line 442  int article_modify(const SECTION_LIST *p
442                  return 0;                  return 0;
443          }          }
444    
         if (!checkpriv(&BBS_priv, p_section->sid, S_POST))  
         {  
                 clearscr();  
                 moveto(1, 1);  
                 prints("您没有权限在本版块发表文章\n");  
                 press_any_key();  
   
                 return 0;  
         }  
   
445          db = db_open();          db = db_open();
446          if (db == NULL)          if (db == NULL)
447          {          {
448                  log_error("db_open() error: %s\n", mysql_error(db));                  log_error("db_open() error: %s\n", mysql_error(db));
449                  return -1;                  ret = -1;
450                    goto cleanup;
451          }          }
452    
453          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
# Line 455  int article_modify(const SECTION_LIST *p Line 459  int article_modify(const SECTION_LIST *p
459          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
460          {          {
461                  log_error("Query article content error: %s\n", mysql_error(db));                  log_error("Query article content error: %s\n", mysql_error(db));
462                  ret = -2;                  ret = -1;
463                  goto cleanup;                  goto cleanup;
464          }          }
465          if ((rs = mysql_use_result(db)) == NULL)          if ((rs = mysql_use_result(db)) == NULL)
466          {          {
467                  log_error("Get article content data failed\n");                  log_error("Get article content data failed\n");
468                  ret = -2;                  ret = -1;
469                  goto cleanup;                  goto cleanup;
470          }          }
471    
# Line 479  int article_modify(const SECTION_LIST *p Line 483  int article_modify(const SECTION_LIST *p
483                  content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0';                  content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0';
484    
485                  // Remove control sequence                  // Remove control sequence
486                  len_content = ctrl_seq_filter(content);                  len_content = str_filter(content, 0);
487    
488                  p_editor_data = editor_data_load(content);                  p_editor_data = editor_data_load(content);
489                  if (p_editor_data == NULL)                  if (p_editor_data == NULL)
490                  {                  {
491                          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]));
492                          ret = -3;                          ret = -1;
493                          goto cleanup;                          goto cleanup;
494                  }                  }
495    
# Line 511  int article_modify(const SECTION_LIST *p Line 515  int article_modify(const SECTION_LIST *p
515                  {                  {
516                          switch (toupper(ch))                          switch (toupper(ch))
517                          {                          {
518                            case KEY_NULL:
519                            case KEY_TIMEOUT:
520                                    goto cleanup;
521                          case CR:                          case CR:
522                                  igetch_reset();                                  igetch_reset();
523                          case 'S':                          case 'S':
# Line 531  int article_modify(const SECTION_LIST *p Line 538  int article_modify(const SECTION_LIST *p
538                  }                  }
539          }          }
540    
541            if (SYS_server_exit) // Do not save data on shutdown
542            {
543                    goto cleanup;
544            }
545    
546          // Allocate buffers in big size          // Allocate buffers in big size
547          content = malloc(ARTICLE_CONTENT_MAX_LEN);          content = malloc(ARTICLE_CONTENT_MAX_LEN);
548          if (content == NULL)          if (content == NULL)
# Line 544  int article_modify(const SECTION_LIST *p Line 556  int article_modify(const SECTION_LIST *p
556          if (len_content < 0)          if (len_content < 0)
557          {          {
558                  log_error("editor_data_save() error\n");                  log_error("editor_data_save() error\n");
559                  ret = -2;                  ret = -1;
560                  goto cleanup;                  goto cleanup;
561          }          }
562    
# Line 623  int article_modify(const SECTION_LIST *p Line 635  int article_modify(const SECTION_LIST *p
635    
636          // Update article          // Update article
637          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
638                           "UPDATE bbs SET CID = %d, length = %ld WHERE AID = %d",                           "UPDATE bbs SET CID = %d, length = %ld, excerption = 0 WHERE AID = %d", // Set excerption = 0 explictly in case of rare condition
639                           p_article_new->cid, len_content, p_article->aid);                           p_article_new->cid, len_content, p_article->aid);
640    
641          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
# Line 661  int article_modify(const SECTION_LIST *p Line 673  int article_modify(const SECTION_LIST *p
673                  goto cleanup;                  goto cleanup;
674          }          }
675    
676            mysql_close(db);
677            db = NULL;
678    
679          clearscr();          clearscr();
680          moveto(1, 1);          moveto(1, 1);
681          prints("修改完成,新内容通常会在%d秒后可见", BBS_section_list_load_interval);          prints("修改完成,新内容通常会在%d秒后可见", BBS_section_list_load_interval);
# Line 724  int article_reply(const SECTION_LIST *p_ Line 739  int article_reply(const SECTION_LIST *p_
739    
740          p_article_new->title[0] = '\0';          p_article_new->title[0] = '\0';
741          snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title);          snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title);
742          len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len);          len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len, 0);
743          title_input[len] = '\0';          title_input[len] = '\0';
744    
745          db = db_open();          db = db_open();
746          if (db == NULL)          if (db == NULL)
747          {          {
748                  log_error("db_open() error: %s\n", mysql_error(db));                  log_error("db_open() error: %s\n", mysql_error(db));
749                  return -1;                  ret = -1;
750                    goto cleanup;
751          }          }
752    
753          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
# Line 741  int article_reply(const SECTION_LIST *p_ Line 757  int article_reply(const SECTION_LIST *p_
757          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
758          {          {
759                  log_error("Query article status error: %s\n", mysql_error(db));                  log_error("Query article status error: %s\n", mysql_error(db));
760                  return -2;                  ret = -1;
761                    goto cleanup;
762          }          }
763          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
764          {          {
765                  log_error("Get article status data failed\n");                  log_error("Get article status data failed\n");
766                  return -2;                  ret = -1;
767                    goto cleanup;
768          }          }
769    
770          if ((row = mysql_fetch_row(rs)))          if ((row = mysql_fetch_row(rs)))
# Line 761  int article_reply(const SECTION_LIST *p_ Line 779  int article_reply(const SECTION_LIST *p_
779    
780          if (topic_locked) // Reply is not allowed          if (topic_locked) // Reply is not allowed
781          {          {
782                    mysql_close(db);
783                    db = NULL;
784    
785                  clearscr();                  clearscr();
786                  moveto(1, 1);                  moveto(1, 1);
787                  prints("该主题谢绝回复");                  prints("该主题谢绝回复");
# Line 778  int article_reply(const SECTION_LIST *p_ Line 799  int article_reply(const SECTION_LIST *p_
799          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
800          {          {
801                  log_error("Query article content error: %s\n", mysql_error(db));                  log_error("Query article content error: %s\n", mysql_error(db));
802                  return -2;                  ret = -1;
803                    goto cleanup;
804          }          }
805          if ((rs = mysql_use_result(db)) == NULL)          if ((rs = mysql_use_result(db)) == NULL)
806          {          {
807                  log_error("Get article content data failed\n");                  log_error("Get article content data failed\n");
808                  return -2;                  ret = -1;
809                    goto cleanup;
810          }          }
811    
812          if ((row = mysql_fetch_row(rs)))          if ((row = mysql_fetch_row(rs)))
# Line 809  int article_reply(const SECTION_LIST *p_ Line 832  int article_reply(const SECTION_LIST *p_
832                  content_f[len] = '\0';                  content_f[len] = '\0';
833    
834                  // Remove control sequence                  // Remove control sequence
835                  len = ctrl_seq_filter(content_f);                  len = str_filter(content_f, 0);
836    
837                  len = snprintf(content, ARTICLE_CONTENT_MAX_LEN,                  len = snprintf(content, ARTICLE_CONTENT_MAX_LEN,
838                                             "\n\n【 在 %s (%s) 的大作中提到: 】\n",                                             "\n\n【 在 %s (%s) 的大作中提到: 】\n",
839                                             p_article->username, p_article->nickname);                                             p_article->username, p_article->nickname);
840    
841                  quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1);                  quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1, 0);
842                  for (i = 0; i < quote_content_lines; i++)                  for (i = 0; i < quote_content_lines; i++)
843                  {                  {
844                          memcpy(content + len, ": ", 2); // quote line prefix                          memcpy(content + len, ": ", 2); // quote line prefix
845                          len += 2;                          len += 2;
846                          memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i]));                          memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i]));
847                          len += (line_offsets[i + 1] - line_offsets[i]);                          len += (line_offsets[i + 1] - line_offsets[i]);
848                            if (content[len - 1] != '\n') // Appennd \n if not exist
849                            {
850                                    content[len] = '\n';
851                                    len++;
852                            }
853                  }                  }
854                  if (content[len - 1] != '\n') // Appennd \n if not exist                  if (content[len - 1] != '\n') // Appennd \n if not exist
855                  {                  {
# Line 837  int article_reply(const SECTION_LIST *p_ Line 865  int article_reply(const SECTION_LIST *p_
865                  if (p_editor_data == NULL)                  if (p_editor_data == NULL)
866                  {                  {
867                          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]));
868                          ret = -3;                          ret = -1;
869                          goto cleanup;                          goto cleanup;
870                  }                  }
871    
# Line 875  int article_reply(const SECTION_LIST *p_ Line 903  int article_reply(const SECTION_LIST *p_
903                  {                  {
904                          switch (toupper(ch))                          switch (toupper(ch))
905                          {                          {
906                            case KEY_NULL:
907                            case KEY_TIMEOUT:
908                                    goto cleanup;
909                          case CR:                          case CR:
910                                  igetch_reset();                                  igetch_reset();
911                                  break;                                  break;
# Line 932  int article_reply(const SECTION_LIST *p_ Line 963  int article_reply(const SECTION_LIST *p_
963                          {                          {
964                                  switch (toupper(ch))                                  switch (toupper(ch))
965                                  {                                  {
966                                    case KEY_NULL:
967                                    case KEY_TIMEOUT:
968                                            goto cleanup;
969                                  case CR:                                  case CR:
970                                          igetch_reset();                                          igetch_reset();
971                                  case 'S':                                  case 'S':
# Line 960  int article_reply(const SECTION_LIST *p_ Line 994  int article_reply(const SECTION_LIST *p_
994                  }                  }
995          }          }
996    
997            if (SYS_server_exit) // Do not save data on shutdown
998            {
999                    goto cleanup;
1000            }
1001    
1002          content = malloc(ARTICLE_CONTENT_MAX_LEN);          content = malloc(ARTICLE_CONTENT_MAX_LEN);
1003          if (content == NULL)          if (content == NULL)
1004          {          {
# Line 972  int article_reply(const SECTION_LIST *p_ Line 1011  int article_reply(const SECTION_LIST *p_
1011          if (len_content < 0)          if (len_content < 0)
1012          {          {
1013                  log_error("editor_data_save() error\n");                  log_error("editor_data_save() error\n");
1014                  ret = -2;                  ret = -1;
1015                  goto cleanup;                  goto cleanup;
1016          }          }
1017    
# Line 1153  int article_reply(const SECTION_LIST *p_ Line 1192  int article_reply(const SECTION_LIST *p_
1192                  goto cleanup;                  goto cleanup;
1193          }          }
1194    
1195            mysql_close(db);
1196            db = NULL;
1197    
1198          clearscr();          clearscr();
1199          moveto(1, 1);          moveto(1, 1);
1200          prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval);          prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval);


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

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