Commit Graph

593 Commits

Author SHA1 Message Date
João Valverde b5d74c69a7 dfilter: Fix error message with non printable ASCII
Before:
    Filter: http.user_agent == açaí
    dftest: "�" was unexpected in this context.

After:
    Filter: http.user_agent == açaí
    dftest: Non-printable ASCII characters may only appear inside double-quotes.

Related with #17770.
2022-02-19 17:49:29 +00:00
João Valverde d8b7d1f821 dfilter: Add aliases "any_eq" and "all_ne" 2021-12-22 14:32:32 +00:00
João Valverde 8b23dd3a3c dfilter: Add an "all equal" operator
To complete the set of equality operators add an "all equal"
operator that matches a frame if all fields match the condition.

The symbol chosen for "all_eq" is "===".
2021-12-22 14:32:32 +00:00
João Valverde c5a19582e4 epan: Convert to use stdio.h from GLib
Replace:
    g_snprintf() -> snprintf()
    g_vsnprintf() -> vsnprintf()
    g_strdup_printf() -> ws_strdup_printf()
    g_strdup_vprintf() -> ws_strdup_vprintf()

This is more portable, user-friendly and faster on platforms
where GLib does not like the native I/O.

Adjust the format string to use macros from intypes.h.
2021-12-19 19:29:53 +00:00
João Valverde 5bba669579 Remove some lingering uses of g_assert()
Also replace some incorrect uses of g_assert_true().

  g_assert_true -> g_assert -> ws_assert
2021-12-16 10:19:45 +00:00
João Valverde f5f8d9ebb6 dfilter: Fix token associativity
TEST_EQ and TEST_NE are unused. Replace by the correct values
and add missing token to string representations.
2021-12-13 01:24:18 +00:00
João Valverde 7cffcfa835 dfilter: Remove a default switch case 2021-12-12 10:16:27 +00:00
João Valverde 60e305d1e1 dfilter: Convert grammar.lemon to 4-space indentation
Add global EditorConfig settings for lemon files.

Add exceptions for the two grammar files that use tab indentation.
2021-12-02 15:48:40 +00:00
João Valverde 3657788cbb dfilter: Add default grammar type 2021-12-01 19:43:30 +00:00
João Valverde 647decd509 dfilter: Avoid double strdup to save token value
Store the lval token value instead.
2021-12-01 19:42:51 +00:00
João Valverde 557cee31fc dfilter: Save lexical token value to syntax tree
Use that for error messages, including any using test operators.

This allows to always use the same name as the user. It avoids
cases where the user write "a && b" and the message is "a and b"
is syntactically invalid.

It should also allow us to be more consistent with the use of
double quotes.
2021-12-01 13:34:01 +00:00
João Valverde 3e0806ca09 dfilter: Remove dfilter_fail_parse()
Instead of requiring a special error function in the parser
just set the syntax_error flag if an error occurs, in any stage
of compilation. Outside of the parser loop it will not be used
but that is fine.
2021-11-30 19:52:05 +00:00
João Valverde a6f978b4d3 dfilter: Remove two stnode replacement functions
One is unused and the other is only used with a corner
case. They are probably not necessary otherwise.
2021-11-30 19:48:47 +00:00
Moshe Kaplan a523135202 epan: Add header files to Doxygen
Add @file markers for epan
headers so that Doxygen will
generate documentation for them.
2021-11-30 08:46:49 +00:00
Moshe Kaplan 40016daeb3 Add files with WS_DLL_PUBLIC to Doxygen part2
Add @file markers for remaining non-dissector
files that contain functions exported with
WS_DLL_PUBLIC so that Doxygen will
generate documentation for them.
2021-11-30 06:47:35 +00:00
João Valverde fbfb4959ae dfilter: Better representation for charconst 2021-11-27 18:38:22 +00:00
João Valverde 352390aa97 dfilter: Need to handle a charconst on the LHS 2021-11-27 17:19:11 +00:00
João Valverde 702c7f0cc8 Remove stale comment. 2021-11-24 10:45:42 +00:00
João Valverde 35ad2e85c8 dfilter: Free a scanner string 2021-11-24 10:06:19 +00:00
João Valverde eb8c3169e7 dfilter: Clean up charconst error message 2021-11-24 09:38:58 +00:00
João Valverde 943c282009 dfilter: Parse character constants in lexer
Invalid character constants should be handled in the lexical scanner.

Todo: See if some code could be shared to parse double quoted strings.

It also fixes some unintuitive type coercions to string. Character
constants should be treated as characters, or maybe integers, or
maybe even throw an invalid comparison error, but coverting to a
literal string or byte array is surprising and not particularly
useful:
  '\xFF' -> "'\xFF'" (equals)
  '\xFF' -> "FF"     (contains)

Before:

    Filter: http.request.method contains "\x63"

    Constants:
    00000 PUT_FVALUE	"c" <FT_STRING> -> reg#1
    (...)

    Filter: http.request.method contains '\x63'

    Constants:
    00000 PUT_FVALUE	"63" <FT_STRING> -> reg#1
    (...)

    Filter: http.request.method == "\x63"

    Constants:
    00000 PUT_FVALUE	"c" <FT_STRING> -> reg#1
    (...)

    Filter: http.request.method == '\x63'

    Constants:
    00000 PUT_FVALUE	"'\\x63'" <FT_STRING> -> reg#1
    (...)

After:

    Filter: http.request.method contains '\x63'

    Constants:
    00000 PUT_FVALUE	"c" <FT_STRING> -> reg#1
    (...)

    Filter: http.request.method == '\x63'

    Constants:
    00000 PUT_FVALUE	"c" <FT_STRING> -> reg#1
    (...)
2021-11-24 08:40:20 +00:00
João Valverde 7028646f9e dfilter: Fix invalid character constant error message
This reverts commit d635ff4933.

A charconst cannot be a value string, for that reason it is not
redundant with unparsed.

Maybe character constants should be parsed in the lexical scanner
instead.

Before:
  Filter: ip.proto == '\g'
  dftest: "'\g'" cannot be found among the possible values for ip.proto.

After:
  Filter: ip.proto == '\g'
  dftest: "'\g'" isn't a valid character constant.
2021-11-23 17:35:40 +00:00
João Valverde 72c5efea1b dfilter: Reject invalid character escape sequences
For double quoted strings. This is consistent with single quote
character constants and the C standard. It also avoids common
mistakes where the superfluous backslash is silently suppressed.
2021-11-23 16:48:02 +00:00
João Valverde bbaa144b3c dfilter: Remove reference to GRegex 2021-11-23 14:08:06 +00:00
João Valverde 3c7894e2a0 dfilter: Add compilation result to log output
Add result output to console log, in addition to intermediate debug
information. This allows tracing the result using the log only.
2021-11-16 13:52:30 +00:00
João Valverde 75bb51eef9 dfilter: Clean up some debug statements, second try
Add just a console entry for check_test(), in a more compact
form.

Remove logging of the call chain. This was partially replaced by the
printout of the syntax tree.
2021-11-16 11:27:04 +00:00
João Valverde c4337d0dc5 dfilter: Give more context for regex error messages 2021-11-16 11:18:09 +00:00
João Valverde 848f4f8e97 dfilter: Cleanup some debug statements
Reduce the verbosity a bit, even with "noisy" level,
and remove some extraneous new lines.
2021-11-14 23:22:42 +00:00
João Valverde 274531820a Move regex code to wsutil 2021-11-14 21:00:59 +00:00
João Valverde b9f2e4b7fa Make PCRE2 a required dependency 2021-11-14 21:00:59 +00:00
João Valverde ed8a02af17 dfilter: Add support for PCRE2
PCRE2 is the future of PCRE. The only advantage of GRegex is that
it comes bundled with GLib, which is not an advantage at all.
PCRE2 is widely available, the GRegex abstractions layer are not a
good fit and abstract things that don't need abstracting or that we
could handle better ourselves, there are open bugs (#12997) and
maintenance is spotty at best.

GRegex comes with many of the problems of bundled code, aggravated by
the fact that it completely falls outside of our control.
2021-11-14 21:00:59 +00:00
João Valverde 77fa0fb23d dfilter: Fixup unexpected end of filter error message
Fixes e7ecc9b9e5.
2021-11-14 15:33:56 +00:00
João Valverde b90e5cf0c7 dfilter: Restore debug syntax tree display
Restore the test stnode representation that was lost in 2db36f8ce0.
2021-11-13 21:23:28 +00:00
João Valverde 01d1cc492e dfilter: Add default case to switch 2021-11-13 11:39:32 +00:00
João Valverde 1a32a75a62 ftypes: Internal headers need to be internal
The header ftypes-int.h should not be used outside of epan/ftypes
because it is a private header.

The functions fvalue_free() and fvalue_cleanup() need not and should
not be macros either.
2021-11-11 03:15:31 +00:00
João Valverde b62d4b8eca dfilter: Change string node display representation again
Adding double quotes to the display output format was probably a mistake.
2021-11-10 03:19:24 +00:00
João Valverde e7ecc9b9e5 dfilter: Clean up error format and exception code
Misc code cleanups. Add some extra stnode functions for increased type
safety. Fix a constness issue with df_lval_value().
2021-11-10 03:18:50 +00:00
João Valverde 63adcf7fb5 dfilter: Clean up function parameters semantic check 2021-11-10 02:12:06 +00:00
João Valverde d0a07881f4 dfilter: Remove unnecessary node conversion
This has never worked AFAICT because functions have never accepted
fvalues, only fields, so converting from unparsed to an fvalue
string is moot, they are both invalid argument types to functions.
2021-11-10 01:23:49 +00:00
João Valverde ac431ec855 dfilter: Remove some debug statements
Normalize the amount of debug code in the module.
2021-11-10 01:23:49 +00:00
João Valverde e965fa32a1 dfilter: Refactor some semantic check code
Try to reorganize the check_relation sub-functions for better
clarity and consistency and less duplication.
2021-11-10 01:23:29 +00:00
João Valverde cd7d06faaf dfilter: Add an assertion 2021-11-09 23:05:56 +00:00
João Valverde 4e399d6508 dfilter: Fix signature of check_relation()
check_relation() has the argument order swapped from every other
relation check, that's confusing.
2021-11-07 23:14:59 +00:00
João Valverde 2db36f8ce0 dfilter: Pass a test_op_t in check_relation() 2021-11-07 22:44:59 +00:00
João Valverde 69c850df51 ftypes: Simplify fvalue_can_*() interface
If an ftype can participate in equala assume it can also participate in
not equals. Use fvalue_can_eq() instead of fvalue_can_ne().

If it can participate in one order comparison it can participate in all.
Replace any comparison with fvalue_can_cmp().
2021-11-07 22:44:59 +00:00
João Valverde 146a840ad1 dfilter: Move a constructor to the grammar file 2021-11-06 11:45:21 +00:00
João Valverde 6823073f7e dfilter: Fix corner case with matches
Previously a chained expression like "a == b matches c" would be
considered syntactically valid. Fix that to be a syntax error.
Only math-like comparisons can be chained.

This also disallows chaining contains expressions.
2021-11-06 11:45:21 +00:00
João Valverde 2d45cb0881 dfilter: Improve some error messages 2021-11-06 11:45:21 +00:00
João Valverde fb490eb172 dfilter: Move regex creation to semcheck 2021-11-06 11:45:21 +00:00
João Valverde d635ff4933 dfilter: Remove redundant STTYPE_CHARCONST syntax node
A charconst uses the same semantic rules as unparsed so just
use the latter to avoid redundancies.

We keep the use of TOKEN_CHARCONST as an optimization to avoid
an unnecessary name resolution (lookup for a registered field with
the same name as the charconst).
2021-10-31 20:33:31 +00:00