Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syslog format use private inline functions for ctype #441

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading