Skip to content

Commit

Permalink
Merge pull request #441 from bazsi/syslog-format-use-private-inline-f…
Browse files Browse the repository at this point in the history
…unctions-for-ctype

Syslog format use private inline functions for ctype
  • Loading branch information
alltilla authored Jan 7, 2025
2 parents 7e02c3a + 131fe51 commit d267fd8
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions modules/syslogformat/syslog-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "logproto/logproto.h"

#include <regex.h>
#include <ctype.h>
#include <string.h>

#define SD_NAME_SIZE 256
Expand All @@ -63,6 +62,24 @@ _skip_char(const guchar **data, gint *left)
return TRUE;
}

static inline gboolean
_isdigit(char c)
{
return c >= '0' && c <= '9';
}

static inline gboolean
_isalpha(char c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

static inline gboolean
_isascii(char c)
{
return c >= 0 && c <= 127;
}

static gint
_skip_chars(const guchar **data, gint *length, const gchar *chars, gint max_len)
{
Expand Down Expand Up @@ -133,7 +150,7 @@ _syslog_format_parse_pri(LogMessage *msg, const guchar **data, gint *length, gui
pri = 0;
while (left && *src != '>')
{
if (isdigit(*src))
if (_isdigit(*src))
{
pri = pri * 10 + ((*src) - '0');
}
Expand Down Expand Up @@ -200,7 +217,7 @@ _syslog_format_parse_cisco_sequence_id(LogMessage *msg, const guchar **data, gin

while (left && *src != ':')
{
if (!isdigit(*src))
if (!_isdigit(*src))
return;
if (!_skip_char(&src, &left))
return;
Expand Down Expand Up @@ -308,7 +325,7 @@ _syslog_format_parse_version(LogMessage *msg, const guchar **data, gint *length)

while (left && *src != ' ')
{
if (isdigit(*src))
if (_isdigit(*src))
{
version = version * 10 + ((*src) - '0');
}
Expand All @@ -332,12 +349,12 @@ static gsize program_name_allowed_spacial_chars_len = G_N_ELEMENTS(program_name_
static inline gboolean
_validate_program_char(const guchar ch, gboolean *has_alpha)
{
if (isalpha(ch))
if (_isalpha(ch))
{
*has_alpha = TRUE;
return TRUE;
}
if (isdigit(ch))
if (_isdigit(ch))
return TRUE;
if (memchr(program_name_allowed_specials, ch, program_name_allowed_spacial_chars_len))
return TRUE;
Expand Down Expand Up @@ -608,15 +625,15 @@ _syslog_format_parse_sd(LogMessage *msg, const guchar **data, gint *length, cons
open_sd++;
do
{
if (!left || !isascii(*src) || *src == '=' || *src == ' ' || *src == ']' || *src == '"')
if (!left || !_isascii(*src) || *src == '=' || *src == ' ' || *src == ']' || *src == '"')
goto error;
/* read sd_id */
pos = 0;
while (left && *src != ' ' && *src != ']')
{
if (pos < sizeof(sd_id_name) - 1 - options->sdata_prefix_len)
{
if (isascii(*src) && *src != '=' && *src != ' ' && *src != ']' && *src != '"')
if (_isascii(*src) && *src != '=' && *src != ' ' && *src != ']' && *src != '"')
{
sd_id_name[pos] = *src;
pos++;
Expand Down Expand Up @@ -664,7 +681,7 @@ _syslog_format_parse_sd(LogMessage *msg, const guchar **data, gint *length, cons
else
goto error;

if (!left || !isascii(*src) || *src == '=' || *src == ' ' || *src == ']' || *src == '"')
if (!left || !_isascii(*src) || *src == '=' || *src == ' ' || *src == ']' || *src == '"')
goto error;

/* read sd-param */
Expand All @@ -673,7 +690,7 @@ _syslog_format_parse_sd(LogMessage *msg, const guchar **data, gint *length, cons
{
if (pos < sizeof(sd_param_name) - 1 - sd_id_len)
{
if (isascii(*src) && *src != '=' && *src != ' ' && *src != ']' && *src != '"')
if (_isascii(*src) && *src != '=' && *src != ' ' && *src != ']' && *src != '"')
{
sd_param_name[pos] = *src;
pos++;
Expand Down Expand Up @@ -968,7 +985,7 @@ _syslog_format_check_framing(LogMessage *msg, const guchar **data, gint *length)
gint left = *length;
gint i = 0;

while (left > 0 && isdigit(*src))
while (left > 0 && _isdigit(*src))
{
if (!_skip_char(&src, &left))
return;
Expand Down

0 comments on commit d267fd8

Please sign in to comment.