Skip to content

Commit

Permalink
codestyle: correct line length to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalWithopf committed Nov 29, 2017
1 parent e4488eb commit 77f9db4
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 73 deletions.
3 changes: 2 additions & 1 deletion CI/check_codestyle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ git clone https://github.com/rsyslog/codestyle
cd codestyle
gcc --std=c99 stylecheck.c -o stylecheck
cd ../..
find . -name "*.[ch]" | xargs _tmp_stylecheck/codestyle/stylecheck -l 120
find . -name "*.[ch]" | xargs _tmp_stylecheck/codestyle/stylecheck -w -f -l 120
rm -rf codestyle
12 changes: 8 additions & 4 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1846,21 +1846,25 @@ PARSER_Parse(CiscoInterfaceSpec)
json_object *json;
if(bHaveInterface) {
CHKN(json = json_object_new_string_len(c+idxInterface, lenInterface));
json_object_object_add_ex(*value, "interface", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "interface", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
}
CHKN(json = json_object_new_string_len(c+idxIP, lenIP));
json_object_object_add_ex(*value, "ip", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
CHKN(json = json_object_new_string_len(c+idxPort, lenPort));
json_object_object_add_ex(*value, "port", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
if(bHaveIP2) {
CHKN(json = json_object_new_string_len(c+idxIP2, lenIP2));
json_object_object_add_ex(*value, "ip2", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "ip2", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
CHKN(json = json_object_new_string_len(c+idxPort2, lenPort2));
json_object_object_add_ex(*value, "port2", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "port2", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
}
if(bHaveUser) {
CHKN(json = json_object_new_string_len(c+idxUser, lenUser));
json_object_object_add_ex(*value, "user", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "user", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
}

success: /* success, persist */
Expand Down
6 changes: 4 additions & 2 deletions src/pdag.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ for(int i = 0 ; i < dag->nparsers ; ++i) { /* TODO: remove when confident enough
ln_parser_t *prs = dag->parsers+i;
LN_DBGPRINTF(dag->ctx, "optimizing %p: field %d type '%s', name '%s': '%s':",
prs->node, i, parserName(prs->prsid), prs->name,
(prs->prsid == PRS_LITERAL) ? ln_DataForDisplayLiteral(dag->ctx, prs->parser_data) : "UNKNOWN");
(prs->prsid == PRS_LITERAL) ? ln_DataForDisplayLiteral(dag->ctx, prs->parser_data)
: "UNKNOWN");

optLitPathCompact(ctx, prs);

Expand Down Expand Up @@ -1020,7 +1021,8 @@ for(int i = 0 ; i < dag->nparsers ; ++i) {
LN_DBGPRINTF(dag->ctx, "%sfield type '%s', name '%s': '%s':", indent,
parserName(prs->prsid),
dag->parsers[i].name,
(prs->prsid == PRS_LITERAL) ? ln_DataForDisplayLiteral(dag->ctx, prs->parser_data) : "UNKNOWN");
(prs->prsid == PRS_LITERAL) ? ln_DataForDisplayLiteral(dag->ctx, prs->parser_data) :
"UNKNOWN");
if(prs->prsid == PRS_REPEAT) {
struct data_Repeat *const data = (struct data_Repeat*) prs->parser_data;
LN_DBGPRINTF(dag->ctx, "%sparser:", indent);
Expand Down
184 changes: 121 additions & 63 deletions src/v1_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,14 @@ _recursive_parser_data_constructor(ln_fieldList_t *node,
r = 0;
done:
if (r != 0) {
if (name == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for recursive/descent field name");
else if (pData == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (args == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (pData->ctx == NULL) ln_dbgprintf(ctx, "recursive/descent normalizer context creation "
if (name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for recursive/descent field name");
else if (pData == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (args == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (pData->ctx == NULL)
ln_dbgprintf(ctx, "recursive/descent normalizer context creation "
"doneed for field: %s", name);
else if (pData->remaining_field == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for remaining-field name for "
Expand Down Expand Up @@ -980,10 +984,15 @@ static ln_ctx child_recursive_parse_ctx_constructor(ln_ctx parent_ctx, pcons_arg
CHKR(ln_v1_loadSamples(ctx, rb));
done:
if (r != 0) {
if (rb == NULL) ln_dbgprintf(parent_ctx, "file-name for descent rulebase not provided for field: %s", field_name);
else if (ctx == NULL) ln_dbgprintf(parent_ctx, "couldn't allocate memory to create descent-field "
"normalizer context for field: %s", field_name);
else ln_dbgprintf(parent_ctx, "couldn't load samples into descent context for field: %s", field_name);
if (rb == NULL)
ln_dbgprintf(parent_ctx, "file-name for descent rulebase not provided for field: %s",
field_name);
else if (ctx == NULL)
ln_dbgprintf(parent_ctx, "couldn't allocate memory to create descent-field normalizer "
"context for field: %s", field_name);
else
ln_dbgprintf(parent_ctx, "couldn't load samples into descent context for field: %s",
field_name);
if (ctx != NULL) ln_exitCtx(ctx);
ctx = NULL;
}
Expand Down Expand Up @@ -1077,7 +1086,8 @@ PARSER(Tokenized)
if (remaining_len > 0) {
remaining_str = json_object_get_string(json_object_get(remaining));
json_object_object_del(json_p, pData->remaining_field);
if (es_strbufcmp(pData->tok_str, (const unsigned char *)remaining_str, es_strlen(pData->tok_str))) {
if (es_strbufcmp(pData->tok_str, (const unsigned char *)remaining_str,
es_strlen(pData->tok_str))) {
json_object_put(remaining);
break;
} else {
Expand Down Expand Up @@ -1219,17 +1229,26 @@ void* tokenized_parser_data_constructor(ln_fieldList_t *node, ln_ctx ctx) {
r = 0;
done:
if (r != 0) {
if (name == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for tokenized-field name");
else if (args == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (pData == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (tok == NULL) ln_dbgprintf(ctx, "token-separator not provided for field: %s", name);
else if (pData->tok_str == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for token-separator "
"for field: %s", name);
else if (field_descr == NULL) ln_dbgprintf(ctx, "field-type not provided for field: %s", name);
else if (field == NULL) ln_dbgprintf(ctx, "couldn't resolve single-token field-type for tokenized field: %s", name);
else if (pData->ctx == NULL) ln_dbgprintf(ctx, "couldn't initialize normalizer-context for field: %s", name);
else if (pData->remaining_field == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for "
"remaining-field-name for field: %s", name);
if (name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for tokenized-field name");
else if (args == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (pData == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (tok == NULL)
ln_dbgprintf(ctx, "token-separator not provided for field: %s", name);
else if (pData->tok_str == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for token-separator "
"for field: %s", name);
else if (field_descr == NULL)
ln_dbgprintf(ctx, "field-type not provided for field: %s", name);
else if (field == NULL)
ln_dbgprintf(ctx, "couldn't resolve single-token field-type for tokenized field: %s", name);
else if (pData->ctx == NULL)
ln_dbgprintf(ctx, "couldn't initialize normalizer-context for field: %s", name);
else if (pData->remaining_field == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for "
"remaining-field-name for field: %s", name);
if (pData) tokenized_parser_data_destructor((void**) &pData);
}
if (name != NULL) free(name);
Expand Down Expand Up @@ -1273,7 +1292,8 @@ PARSER(Regex)
if (pData->consume_group != pData->return_group) {
char* val = NULL;
if((val = strndup(str + ovector[2 * pData->return_group],
ovector[2 * pData->return_group + 1] - ovector[2 * pData->return_group])) == NULL) {
ovector[2 * pData->return_group + 1] -
ovector[2 * pData->return_group])) == NULL) {
free(ovector);
FAIL(LN_NOMEM);
}
Expand Down Expand Up @@ -1342,22 +1362,31 @@ void* regex_parser_data_constructor(ln_fieldList_t *node, ln_ctx ctx) {
pcons_unescape_arg(args, 0);
CHKN(exp = pcons_arg_copy(args, 0, NULL));

if ((grp_parse_err = regex_parser_configure_consume_and_return_group(args, pData)) != NULL) FAIL(LN_BADCONFIG);
if ((grp_parse_err = regex_parser_configure_consume_and_return_group(args, pData)) != NULL)
FAIL(LN_BADCONFIG);

CHKN(pData->re = pcre_compile(exp, 0, &error, &erroffset, NULL));

pData->max_groups = ((pData->consume_group > pData->return_group) ? pData->consume_group : pData->return_group) + 1;
pData->max_groups = ((pData->consume_group > pData->return_group) ? pData->consume_group :
pData->return_group) + 1;
r = 0;
done:
if (r != 0) {
if (name == NULL) ln_dbgprintf(ctx, "couldn't allocate memory regex-field name");
else if (! ctx->opts & LN_CTXOPT_ALLOW_REGEX) ln_dbgprintf(ctx, "regex support is not enabled for: '%s' "
"(please check lognorm context initialization)", name);
else if (pData == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (args == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (unescaped_exp == NULL) ln_dbgprintf(ctx, "regular-expression missing for field: '%s'", name);
else if (exp == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for regex-string for field: '%s'", name);
else if (grp_parse_err != NULL) ln_dbgprintf(ctx, "%s for: '%s'", grp_parse_err, name);
if (name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory regex-field name");
else if (! ctx->opts & LN_CTXOPT_ALLOW_REGEX)
ln_dbgprintf(ctx, "regex support is not enabled for: '%s' "
"(please check lognorm context initialization)", name);
else if (pData == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (args == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (unescaped_exp == NULL)
ln_dbgprintf(ctx, "regular-expression missing for field: '%s'", name);
else if (exp == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for regex-string for field: '%s'", name);
else if (grp_parse_err != NULL)
ln_dbgprintf(ctx, "%s for: '%s'", grp_parse_err, name);
else if (pData->re == NULL)
ln_dbgprintf(ctx, "couldn't compile regex(encountered error '%s' at char '%d' in pattern) "
"for regex-matched field: '%s'", error, erroffset, name);
Expand Down Expand Up @@ -1506,16 +1535,23 @@ void* interpret_parser_data_constructor(ln_fieldList_t *node, ln_ctx ctx) {
r = 0;
done:
if (r != 0) {
if (name == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for interpret-field name");
else if (pData == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (args == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (type_str == NULL) ln_dbgprintf(ctx, "no type provided for interpretation of field: %s", name);
else if (bad_interpret != 0) ln_dbgprintf(ctx, "interpretation to unknown type '%s' requested for field: %s",
type_str, name);
else if (field_type == NULL) ln_dbgprintf(ctx, "field-type to actually match the content not provided for "
"field: %s", name);
else if (pData->ctx == NULL) ln_dbgprintf(ctx, "couldn't instantiate the normalizer context for matching "
"field: %s", name);
if (name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for interpret-field name");
else if (pData == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (args == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (type_str == NULL)
ln_dbgprintf(ctx, "no type provided for interpretation of field: %s", name);
else if (bad_interpret != 0)
ln_dbgprintf(ctx, "interpretation to unknown type '%s' requested for field: %s",
type_str, name);
else if (field_type == NULL)
ln_dbgprintf(ctx, "field-type to actually match the content not provided for "
"field: %s", name);
else if (pData->ctx == NULL)
ln_dbgprintf(ctx, "couldn't instantiate the normalizer context for matching "
"field: %s", name);

interpret_parser_data_destructor((void**) &pData);
}
Expand Down Expand Up @@ -1662,26 +1698,37 @@ static struct suffixed_parser_data_s* _suffixed_parser_data_constructor(ln_field
r = 0;
done:
if (r != 0) {
if (name == NULL) ln_dbgprintf(ctx, "couldn't allocate memory suffixed-field name");
else if (pData == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
if (name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory suffixed-field name");
else if (pData == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for parser-data for field: %s", name);
else if (pData->value_field_name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for value-field's name for field: %s", name);
else if (pData->suffix_field_name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for suffix-field's name for field: %s", name);
else if (args == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (escaped_tokenizer == NULL) ln_dbgprintf(ctx, "suffix token-string missing for field: '%s'", name);
else if (args == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (escaped_tokenizer == NULL)
ln_dbgprintf(ctx, "suffix token-string missing for field: '%s'", name);
else if (tokenizer == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for unescaping token-string for field: '%s'", name);
else if (uncopied_suffixes_str == NULL) ln_dbgprintf(ctx, "suffix-list missing for field: '%s'", name);
else if (suffixes_str == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for suffix-list for field: '%s'", name);
else if (pData->nsuffix == 0) ln_dbgprintf(ctx, "could't read suffix-value(s) for field: '%s'", name);
ln_dbgprintf(ctx, "couldn't allocate memory for unescaping token-string for field: '%s'",
name);
else if (uncopied_suffixes_str == NULL)
ln_dbgprintf(ctx, "suffix-list missing for field: '%s'", name);
else if (suffixes_str == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for suffix-list for field: '%s'", name);
else if (pData->nsuffix == 0)
ln_dbgprintf(ctx, "could't read suffix-value(s) for field: '%s'", name);
else if (pData->suffix_offsets == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for suffix-list element references for field: '%s'", name);
ln_dbgprintf(ctx, "couldn't allocate memory for suffix-list element references for field: "
"'%s'", name);
else if (pData->suffix_lengths == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for suffix-list element lengths for field: '%s'", name);
ln_dbgprintf(ctx, "couldn't allocate memory for suffix-list element lengths for field: '%s'",
name);
else if (pData->suffixes_str == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for suffix-list for field: '%s'", name);
else if (field_type == NULL) ln_dbgprintf(ctx, "field-type declaration missing for field: '%s'", name);
else if (field_type == NULL)
ln_dbgprintf(ctx, "field-type declaration missing for field: '%s'", name);
else if (pData->ctx == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for normalizer-context for field: '%s'", name);
suffixed_parser_data_destructor((void**)&pData);
Expand Down Expand Up @@ -1712,17 +1759,24 @@ void* named_suffixed_parser_data_constructor(ln_fieldList_t *node, ln_ctx ctx) {
CHKN(remaining_args = pcons_arg(args, 2, NULL));
CHKN(unnamed_suffix_args = es_newStrFromCStr(remaining_args, strlen(remaining_args)));

CHKN(pData = _suffixed_parser_data_constructor(node, ctx, unnamed_suffix_args, value_field_name, suffix_field_name));
CHKN(pData = _suffixed_parser_data_constructor(node, ctx, unnamed_suffix_args, value_field_name,
suffix_field_name));
r = 0;
done:
if (r != 0) {
if (name == NULL) ln_dbgprintf(ctx, "couldn't allocate memory named_suffixed-field name");
else if (args == NULL) ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (value_field_name == NULL) ln_dbgprintf(ctx, "key-name for value not provided for field: %s", name);
else if (suffix_field_name == NULL) ln_dbgprintf(ctx, "key-name for suffix not provided for field: %s", name);
if (name == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory named_suffixed-field name");
else if (args == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for argument-parsing for field: %s", name);
else if (value_field_name == NULL)
ln_dbgprintf(ctx, "key-name for value not provided for field: %s", name);
else if (suffix_field_name == NULL)
ln_dbgprintf(ctx, "key-name for suffix not provided for field: %s", name);
else if (unnamed_suffix_args == NULL)
ln_dbgprintf(ctx, "couldn't allocate memory for unnamed-suffix-field args for field: %s", name);
else if (pData == NULL) ln_dbgprintf(ctx, "couldn't create parser-data for field: %s", name);
ln_dbgprintf(ctx, "couldn't allocate memory for unnamed-suffix-field args for field: %s",
name);
else if (pData == NULL)
ln_dbgprintf(ctx, "couldn't create parser-data for field: %s", name);
suffixed_parser_data_destructor((void**)&pData);
}
if (unnamed_suffix_args != NULL) free(unnamed_suffix_args);
Expand Down Expand Up @@ -2026,21 +2080,25 @@ PARSER(CiscoInterfaceSpec)
json_object *json;
if(bHaveInterface) {
CHKN(json = json_object_new_string_len(c+idxInterface, lenInterface));
json_object_object_add_ex(*value, "interface", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "interface", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
}
CHKN(json = json_object_new_string_len(c+idxIP, lenIP));
json_object_object_add_ex(*value, "ip", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
CHKN(json = json_object_new_string_len(c+idxPort, lenPort));
json_object_object_add_ex(*value, "port", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
if(bHaveIP2) {
CHKN(json = json_object_new_string_len(c+idxIP2, lenIP2));
json_object_object_add_ex(*value, "ip2", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "ip2", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
CHKN(json = json_object_new_string_len(c+idxPort2, lenPort2));
json_object_object_add_ex(*value, "port2", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "port2", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
}
if(bHaveUser) {
CHKN(json = json_object_new_string_len(c+idxUser, lenUser));
json_object_object_add_ex(*value, "user", json, JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
json_object_object_add_ex(*value, "user", json,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
}

success: /* success, persist */
Expand Down
3 changes: 2 additions & 1 deletion src/v1_ptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,8 @@ LN_DBGPRINTF(tree->ctx, "%zu: enter parser, tree %p", offs, tree);
}
if(left > 0 && left < r)
r = left;
LN_DBGPRINTF(tree->ctx, "%zu nonmatch, backtracking required, left=%d, r now %d", offs, left, r);
LN_DBGPRINTF(tree->ctx, "%zu nonmatch, backtracking required, left=%d, r now %d",
offs, left, r);
++tree->stats.backtracked;
}
}
Expand Down
Loading

0 comments on commit 77f9db4

Please sign in to comment.