/[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.31 by sysadm, Wed Oct 29 03:23:39 2025 UTC Revision 1.32 by sysadm, Wed Oct 29 04:08:36 2025 UTC
# Line 301  int lml_render(const char *str_in, char Line 301  int lml_render(const char *str_in, char
301                          tag_start_pos = i;                          tag_start_pos = i;
302                          tag_name_pos = i + 1;                          tag_name_pos = i + 1;
303                  }                  }
304                  else if (!lml_tag_disabled && str_in[i] == ']')                  else if (!lml_tag_disabled && str_in[i] == ']' && tag_name_pos >= 0)
305                  {                  {
306                          if (tag_name_pos >= 0)                          tag_end_pos = i;
                         {  
                                 tag_end_pos = i;  
307    
308                                  // Skip space characters                          // Skip space characters
309                                  while (str_in[tag_name_pos] == ' ')                          while (str_in[tag_name_pos] == ' ')
310                                  {                          {
311                                          tag_name_pos++;                                  tag_name_pos++;
312                                  }                          }
313    
314                                  for (tag_name_found = 0, k = 0; k < LML_TAG_COUNT; k++)                          for (tag_name_found = 0, k = 0; k < LML_TAG_COUNT; k++)
315                            {
316                                    if (strncasecmp(lml_tag_def[k].tag_name, str_in + tag_name_pos, (size_t)lml_tag_name_len[k]) == 0)
317                                  {                                  {
318                                          if (strncasecmp(lml_tag_def[k].tag_name, str_in + tag_name_pos, (size_t)lml_tag_name_len[k]) == 0)                                          tag_param_pos = -1;
319                                            switch (str_in[tag_name_pos + lml_tag_name_len[k]])
320                                          {                                          {
321                                                  tag_param_pos = -1;                                          case ' ':
322                                                  switch (str_in[tag_name_pos + lml_tag_name_len[k]])                                                  tag_name_found = 1;
323                                                    tag_param_pos = tag_name_pos + lml_tag_name_len[k] + 1;
324                                                    while (str_in[tag_param_pos] == ' ')
325                                                    {
326                                                            tag_param_pos++;
327                                                    }
328                                                    strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN));
329                                                    tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0';
330                                            case ']':
331                                                    tag_name_found = 1;
332                                                    if (tag_param_pos == -1 && lml_tag_def[k].tag_output != NULL && lml_tag_def[k].default_param != NULL) // Apply default param if not defined
333                                                    {
334                                                            strncpy(tag_param_buf, lml_tag_def[k].default_param, LML_TAG_PARAM_BUF_LEN - 1);
335                                                            tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0';
336                                                    }
337                                                    if (!quote_mode)
338                                                    {
339                                                            if (lml_tag_def[k].tag_output != NULL)
340                                                            {
341                                                                    tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].tag_output, tag_param_buf);
342                                                            }
343                                                            else if (lml_tag_def[k].tag_filter_cb != NULL)
344                                                            {
345                                                                    tag_output_len = lml_tag_def[k].tag_filter_cb(
346                                                                            lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 0);
347                                                            }
348                                                            else
349                                                            {
350                                                                    tag_output_len = 0;
351                                                            }
352                                                    }
353                                                    else // if (quote_mode)
354                                                    {
355                                                            if (lml_tag_def[k].quote_mode_output != NULL)
356                                                            {
357                                                                    tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].quote_mode_output, tag_param_buf);
358                                                            }
359                                                            else if (lml_tag_def[k].tag_filter_cb != NULL)
360                                                            {
361                                                                    tag_output_len = lml_tag_def[k].tag_filter_cb(
362                                                                            lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 1);
363                                                            }
364                                                            else
365                                                            {
366                                                                    tag_output_len = 0;
367                                                            }
368                                                    }
369                                                    if (j + tag_output_len >= buf_len)
370                                                  {                                                  {
371                                                  case ' ':                                                          log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len);
372                                                          tag_name_found = 1;                                                          str_out[j] = '\0';
373                                                          tag_param_pos = tag_name_pos + lml_tag_name_len[k] + 1;                                                          return j;
                                                         while (str_in[tag_param_pos] == ' ')  
                                                         {  
                                                                 tag_param_pos++;  
                                                         }  
                                                         strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN));  
                                                         tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0';  
                                                 case ']':  
                                                         tag_name_found = 1;  
                                                         if (tag_param_pos == -1 && lml_tag_def[k].tag_output != NULL && lml_tag_def[k].default_param != NULL) // Apply default param if not defined  
                                                         {  
                                                                 strncpy(tag_param_buf, lml_tag_def[k].default_param, LML_TAG_PARAM_BUF_LEN - 1);  
                                                                 tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0';  
                                                         }  
                                                         if (!quote_mode)  
                                                         {  
                                                                 if (lml_tag_def[k].tag_output != NULL)  
                                                                 {  
                                                                         tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].tag_output, tag_param_buf);  
                                                                 }  
                                                                 else if (lml_tag_def[k].tag_filter_cb != NULL)  
                                                                 {  
                                                                         tag_output_len = lml_tag_def[k].tag_filter_cb(  
                                                                                 lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 0);  
                                                                 }  
                                                                 else  
                                                                 {  
                                                                         tag_output_len = 0;  
                                                                 }  
                                                         }  
                                                         else // if (quote_mode)  
                                                         {  
                                                                 if (lml_tag_def[k].quote_mode_output != NULL)  
                                                                 {  
                                                                         tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].quote_mode_output, tag_param_buf);  
                                                                 }  
                                                                 else if (lml_tag_def[k].tag_filter_cb != NULL)  
                                                                 {  
                                                                         tag_output_len = lml_tag_def[k].tag_filter_cb(  
                                                                                 lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 1);  
                                                                 }  
                                                                 else  
                                                                 {  
                                                                         tag_output_len = 0;  
                                                                 }  
                                                         }  
                                                         if (j + tag_output_len >= buf_len)  
                                                         {  
                                                                 log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len);  
                                                                 str_out[j] = '\0';  
                                                                 return j;  
                                                         }  
                                                         memcpy(str_out + j, tag_output_buf, (size_t)tag_output_len);  
                                                         j += tag_output_len;  
                                                         break;  
                                                 default: // tag_name not match  
                                                         continue;  
374                                                  }                                                  }
375                                                    memcpy(str_out + j, tag_output_buf, (size_t)tag_output_len);
376                                                    j += tag_output_len;
377                                                  break;                                                  break;
378                                            default: // tag_name not match
379                                                    continue;
380                                          }                                          }
381                                            break;
382                                  }                                  }
383                            }
384    
385                                  if (!tag_name_found)                          if (!tag_name_found)
386                            {
387                                    tag_output_len = tag_end_pos - tag_start_pos + 1;
388                                    if (j + tag_output_len >= buf_len)
389                                  {                                  {
390                                          tag_output_len = tag_end_pos - tag_start_pos + 1;                                          log_error("Buffer is not longer enough for output string %ld >= %d\n", j + tag_output_len, buf_len);
391                                          if (j + tag_output_len >= buf_len)                                          str_out[j] = '\0';
392                                          {                                          return j;
                                                 log_error("Buffer is not longer enough for output string %ld >= %d\n", j + tag_output_len, buf_len);  
                                                 str_out[j] = '\0';  
                                                 return j;  
                                         }  
   
                                         memcpy(str_out + j, str_in + tag_start_pos, (size_t)tag_output_len);  
                                         j += tag_output_len;  
393                                  }                                  }
394    
395                                  tag_start_pos = -1;                                  memcpy(str_out + j, str_in + tag_start_pos, (size_t)tag_output_len);
396                                  tag_name_pos = -1;                                  j += tag_output_len;
397                          }                          }
398    
399                            tag_start_pos = -1;
400                            tag_name_pos = -1;
401                  }                  }
402                  else if (lml_tag_disabled || tag_name_pos == -1) // not in LML tag                  else if (lml_tag_disabled || tag_name_pos == -1) // not in LML tag
403                  {                  {


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

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