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

Diff of /lbbs/src/lml.c

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

Revision 1.1 by sysadm, Mon Jun 2 15:01:55 2025 UTC Revision 1.2 by sysadm, Mon Jun 2 23:49:47 2025 UTC
# Line 16  Line 16 
16    
17  #include "lml.h"  #include "lml.h"
18  #include "log.h"  #include "log.h"
19    #include "common.h"
20  #include <stdio.h>  #include <stdio.h>
21  #include <string.h>  #include <string.h>
22  #include <sys/param.h>  #include <sys/param.h>
23    
24  #define LML_TAG_PARAM_MAX_LEN 20  #define LML_TAG_PARAM_BUF_LEN 256
25  #define LML_TAG_OUTPUT_BUF_LEN 256  #define LML_TAG_OUTPUT_BUF_LEN 1024
26    
27  #define LML_TAG_COUNT 21  #define LML_TAG_COUNT 19
28    
29  const static char *LML_tag_name[][2] = {  const static char *LML_tag_def[][3] = {
30          {"left", "["},          {"left", "[", ""},
31          {"right", "]"},          {"right", "]", NULL},
32          {"underline", "\033[4m"},          {"underline", "\033[4m", ""},
33          {"/underline", "\033[24m"},          {"/underline", "\033[24m", NULL},
34          {"u", "\033[4m"},          {"u", "\033[4m", ""},
35          {"/u", "\033[24m"},          {"/u", "\033[24m", NULL},
36          {"url", ""},          {"url", "", ""},
37          {"/url", "(链接: %s)"},          {"/url", "(链接: %s)", NULL},
38          {"link", ""},          {"link", "", ""},
39          {"/link", "(链接: %s)"},          {"/link", "(链接: %s)", NULL},
40          {"email", ""},          {"email", "", ""},
41          {"/email", "(Email: %s)"},          {"/email", "(Email: %s)", NULL},
42          {"user", ""},          {"user", "", ""},
43          {"/user", "(用户: %s)"},          {"/user", "(用户: %s)", NULL},
44          {"article", ""},          {"article", "", ""},
45          {"/article", "(文章: %s)"},          {"/article", "(文章: %s)", NULL},
46          {"hide", ""},          {"image", "(图片: %s)", ""},
47          {"/hide", ""},          {"flash", "(Flash: %s)", ""},
48          {"image", "(图片: %s)"},          {"bwf", "\033[31m****\033[m", ""},
         {"flash", "(Flash: %s)"},  
         {"bwf", "\033[31m****\033[m"},  
49  };  };
50    
51  static int LML_tag_name_len[LML_TAG_COUNT];  static int LML_tag_name_len[LML_TAG_COUNT];
# Line 60  inline static void lml_init(void) Line 59  inline static void lml_init(void)
59          {          {
60                  for (i = 0; i < LML_TAG_COUNT; i++)                  for (i = 0; i < LML_TAG_COUNT; i++)
61                  {                  {
62                          LML_tag_name_len[i] = (int)strlen(LML_tag_name[i][0]);                          LML_tag_name_len[i] = (int)strlen(LML_tag_def[i][0]);
63                  }                  }
64    
65                  LML_init = 1;                  LML_init = 1;
# Line 69  inline static void lml_init(void) Line 68  inline static void lml_init(void)
68    
69  int lml_plain(const char *str_in, char *str_out, int buf_len)  int lml_plain(const char *str_in, char *str_out, int buf_len)
70  {  {
71          char tag_param_buf[LML_TAG_PARAM_MAX_LEN + 1];          char tag_param_buf[LML_TAG_PARAM_BUF_LEN];
72          char tag_output_buf[LML_TAG_OUTPUT_BUF_LEN];          char tag_output_buf[LML_TAG_OUTPUT_BUF_LEN];
73          int i;          int i;
74          int j = 0;          int j = 0;
75          int k;          int k;
76          int tag_start_pos = -1;          int tag_start_pos = -1;
77          int tag_end_pos = -1;          int tag_end_pos = -1;
78          int tag_param_pos;          int tag_param_pos = -1;
79          int tag_output_len;          int tag_output_len;
80    
81          lml_init();          lml_init();
# Line 101  int lml_plain(const char *str_in, char * Line 100  int lml_plain(const char *str_in, char *
100    
101                                  for (k = 0; k < LML_TAG_COUNT; k++)                                  for (k = 0; k < LML_TAG_COUNT; k++)
102                                  {                                  {
103                                          if (strncasecmp(LML_tag_name[k][0], str_in + tag_start_pos, (size_t)LML_tag_name_len[k]) == 0)                                          if (strncasecmp(LML_tag_def[k][0], str_in + tag_start_pos, (size_t)LML_tag_name_len[k]) == 0)
104                                          {                                          {
105                                                    tag_param_pos = -1;
106                                                  switch (str_in[tag_start_pos + LML_tag_name_len[k]])                                                  switch (str_in[tag_start_pos + LML_tag_name_len[k]])
107                                                  {                                                  {
108                                                  case ' ':                                                  case ' ':
# Line 111  int lml_plain(const char *str_in, char * Line 111  int lml_plain(const char *str_in, char *
111                                                          {                                                          {
112                                                                  tag_param_pos++;                                                                  tag_param_pos++;
113                                                          }                                                          }
114                                                          if (tag_end_pos - tag_param_pos > 0)                                                          strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN));
115                                                            tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0';
116                                                    case ']':
117                                                            if (tag_param_pos == -1 && LML_tag_def[k][2] != NULL) // Apply default param if not defined
118                                                          {                                                          {
119                                                                  strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_MAX_LEN));                                                                  strncpy(tag_param_buf, LML_tag_def[k][2], LML_TAG_PARAM_BUF_LEN - 1);
120                                                                  tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_MAX_LEN)] = '\0';                                                                  tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0';
121                                                          }                                                          }
122                                                  case ']':                                                          tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][1], tag_param_buf);
                                                         tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_name[k][1], tag_param_buf);  
123                                                          if (j + tag_output_len >= buf_len - 1)                                                          if (j + tag_output_len >= buf_len - 1)
124                                                          {                                                          {
125                                                                  log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len - 1);                                                                  log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len - 1);


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

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