Commit Graph

89 Commits

Author SHA1 Message Date
João Valverde c1cede8d7c epan: Format column string input for display.
Format the input for display, by escaping some non printable characters,
using ws_label_strcpy().

In some cases with vsnprintf() this requires using a temporary buffer.

Add some debug checks for invalid UTF-8 errors.

The intention here is to pass dissection data directly to the column
API, and the column functions are responsible for formatting that
data for display. This avoids having to call format_text() before
adding a string to a column and separates the concerns better.
Display formatting is an UI concern.
2022-10-26 13:28:19 +01:00
João Valverde 92e1357bb4 Rename ws_label_strcat() to ws_label_strcpy()
The semantics of ws_label_strcat() are closer to g_strlcpy() so
rename the function to reflect that.
2022-10-26 13:12:35 +01:00
João Valverde 603354203b epan/proto: Replace format text()
The proto.h APIs expect valid UTF-8 so replace uses of format_text()
with a label copy function that just does formatting and does not
check for encoding errors. Avoid multiple levels of temporary
string allocations.

Make sure the copy does not truncate a multibyte character and
produce invalid strings. Add debug checks for UTF-8 encoding errors
instead.

We escape C0 and C1 control codes (because control codes)
and ASCII whitespace (and bell).

Overall the goal is to be more efficient and optimized and help
detect misuse of APIs by passing invalid UTF-8.

Add a unit test for ws_label_strcat.
2022-10-20 20:05:15 +01:00
João Valverde 15634c0b46 Move format_text() to libwsutil and add unit tests 2022-09-28 21:44:27 +00:00
João Valverde 9345bcdae5 epan: Change signature of format_text()
Replace "const guchar *" with "const char *".
2022-09-28 19:28:28 +01:00
João Valverde cdfa3116d2 epan: Update format_text() API documentation 2022-09-28 00:47:25 +00:00
Anders Broman cda3a3dbe9 strutil.h: Fix function description. 2022-09-07 08:31:20 +02:00
John Thacker 95b45b2555 Qt: Add percent-encoding to Show Packet Bytes
Add Percent-encoding to the list of encoding types that Show
Packet Bytes can handle.

There's a function added to glib 2.66 to handle this for arbitrary
bytes that might have internal nulls (and which allows the result
to be non UTF-8), but we don't require that version yet, so extend
the existing function.

Related to #1084
2022-09-03 17:25:28 +00:00
João Valverde 76186f16fb epan: Rewrite format_text_chr() using standard APIs 2021-12-03 10:18:37 +00:00
João Valverde a9c36dfb75 epan: Remove unused format_uri() function
Used with the GTK GUI, not used for a long time.
2021-11-30 22:07:09 +00:00
João Valverde 37f2a86207 Move string_or_null() to wsutil 2021-11-29 18:37:03 +00:00
João Valverde dcbd79584d epan/str_util: Remove unused functions
Remove ws_strdup_escape_char(). I don't think it is generic enough to keep,
and it does not seem very efficient either.

Remove string_replace(). This function was used in the GTK GUI.
2021-11-29 18:37:03 +00:00
João Valverde 44121e2c3b Move escape_string() to wsutil
Move this utility function to wsutil. Rename to
ws_escape_string().

Also add tests.
2021-11-29 17:47:53 +00:00
João Valverde ef8125e3ae Move two functions from epan to wsutil/str_util
Move epan_memmem() and epan_strcasestr() to wsutil/str_util.
Rename to ws_memmem() and ws_strcasestr(). Add compile time
check for a system implementation and use that if available.

We invoke those functions using a wrapper to avoid exposing
_GNU_SOURCE outside of the implementation.
2021-11-28 12:32:51 +00:00
João Valverde 1fc621e38d epan: Fix crash with upper-case protocol filter names
Registering a preference module for a protocol filter name with
upper case letters aborts the program. Relax this restriction to
conform with the rules for protocols. The recommendation is still
to use all lower-case letters.

Fixes 070aeddf76.
2021-11-04 16:29:34 +00:00
João Valverde 925e01b23f Remove duplicate format_size() function
We have two format_size()s, with and without wmem scoped memory.
Move the wmem version to wsutil and add a convenience macro to
use g_malloc()ed memory.
2021-07-26 14:56:11 +00:00
João Valverde 133b0c583f Move epan/wmem/wmem_scopes.h to epan/
This header was installed incorrectly to epan/wmem_scopes.h.

Instead of creating additional installation rules for a single
header in a subfolder (kept for backward compatibility) just
rename the standard "epan/wmem/wmem.h" include to
"epan/wmem_scopes.h" and fix the documentation.

Now the header is installed *correctly* to epan/wmem_scopes.h.
2021-07-26 14:56:11 +00:00
Guy Harris 35418a73f7 Add format_text_string(), which gets the length with strlen().
format_text(alloc, string, strlen(string)) is a common idiom; provide
format_text_string(), which does the strlen(string) for you.  (Any
string used in a %s to set the text of a protocol tree item, if it was
directly extracted from the packet, should be run through a format_text
routine, to ensure that it's valid UTF-8 and that control characters are
handled correctly.)

Update comments while we're at it.

Change-Id: Ia8549efa1c96510ffce97178ed4ff7be4b02eb6e
Reviewed-on: https://code.wireshark.org/review/38202
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-20 07:24:32 +00:00
Michael Mann f509a83381 Add format_size_wmem
It's a "wmem version" of format_size (from wsutil/str_util.h).

Also improved the flexibility in formatting of format_size() to handle future
needs of format_size_wmem

Ping-Bug: 15360
Change-Id: Id9977bbd7ec29375bbac955f685d46e75b0cef2c
Reviewed-on: https://code.wireshark.org/review/31233
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-12-02 05:01:16 +00:00
Dario Lombardo 55c68ee69c epan: use SPDX indentifiers.
Skipping dissectors dir for now.

Change-Id: I717b66bfbc7cc81b83f8c2cbc011fcad643796aa
Reviewed-on: https://code.wireshark.org/review/25694
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 19:29:45 +00:00
Michael Mann 148fb1acf4 Add wmem allocator parameter to format_uri
Change-Id: Ic6de84a37b501e9c62a7d37071b2b081a1a1dd50
Reviewed-on: https://code.wireshark.org/review/19885
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-31 17:08:54 +00:00
Michael Mann 51a3014225 format_text_wmem -> format_text
All cases of the "original" format_text have been handled to add the
proper wmem allocator scope.  Remove the "original" format_text
and replace it with one that has a wmem allocator as a parameter.

Change-Id: I278b93bcb4a17ff396413b75cd332f5fc2666719
Reviewed-on: https://code.wireshark.org/review/19884
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-31 17:08:47 +00:00
Michael Mann d802b5b0ec Add format_text_wmem.
This allows for a wmem_allocator for users of format_text who want
it (dissectors for wmem_packet_scope()).  This lessens the role of
current format_text functionality in hopes that it will eventually
be replaced.

Change-Id: I970557a65e32aa79634a3fcc654ab641b871178e
Reviewed-on: https://code.wireshark.org/review/19855
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-31 02:26:35 +00:00
Michael Mann f789c91a5e Have format_text_wsp use wmem allocated memory.
format_text_wsp is fed into by tvb_format_text_wsp and tvb_format_stringzpad_wsp
so those functions need to add a wmem allocated parameter as well.
Most of the changes came from tvb_format_text_wsp and tvb_format_stringzpad_wsp
being changed more so than format_text_wsp.

Change-Id: I52214ca107016f0e96371a9a8430aa89336f91d7
Reviewed-on: https://code.wireshark.org/review/19851
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-30 02:25:45 +00:00
Michael Mann c44c8f9e6c Have format_text_chr use wmem allocated memory.
Change-Id: Idcea59f6fc84238f04d9ffc11a0088ef97beec0c
Reviewed-on: https://code.wireshark.org/review/19844
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-30 00:05:39 +00:00
João Valverde 4c330cc0e4 Fix constness
Change-Id: I29723dae83373768edd254c60e48a717abf20694
Reviewed-on: https://code.wireshark.org/review/13436
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2016-01-20 16:12:07 +00:00
Hadriel Kaplan f52626cc83 Add tvb_get and proto_tree_add for string-encoded byte arrays
This commit adds tvb_get_string_bytes and proto_tree_add_bytes_item routines for
getting GByteArrays fields from the tvb when they are encoded in ASCII hex string form.

The proto_tree_add_bytes_item routine is also usable for normal
binary encoded byte arrays, and has the advantage of retrieving
the array values even if there's no proto tree.

It also exposes the routines to Lua, both so that a Lua script can take
advantage of this, but also so I can write a testsuite to test the functions.

Change-Id: I112a038653df6482a5d0ebe7c95708f207319e20
Reviewed-on: https://code.wireshark.org/review/1158
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-04-17 14:04:19 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Jakub Zawadzki d6da7a01b1 Fix warnings + remove some v. old comment from strutil.h
svn path=/trunk/; revision=54078
2013-12-13 23:11:14 +00:00
Alexis La Goutte bd5f16acf4 Fix (-W)documentation error found by Clang
../../epan/strutil.h:95:11: error: parameter 'line' not found in the function declaration [-Werror,-Wdocumentation]
 * @param line A pointer to the input string
          ^~~~
../../epan/strutil.h:95:11: note: did you mean 'string'?
 * @param line A pointer to the input string
          ^~~~
          string

svn path=/trunk/; revision=53721
2013-12-02 13:46:20 +00:00
Alexis La Goutte e13ef4109d Fix typo (for generated Documentation)
svn path=/trunk/; revision=53268
2013-11-12 09:23:13 +00:00
Jakub Zawadzki 7b64bcf0b8 Move prototype of bytes_to_str, bytes_to_str_punct to correct header.
svn path=/trunk/; revision=53214
2013-11-10 09:44:02 +00:00
Jakub Zawadzki 0b0bbf0965 Replace STRINGIFY with glib version.
svn path=/trunk/; revision=53193
2013-11-09 14:37:13 +00:00
Jakub Zawadzki 3b2e519422 Remove comment (leftovers from r49444) + add missing WS_DLL_PUBLIC for adler32
(modifing files to be commited when svn commit is already running is no good).

svn path=/trunk/; revision=53192
2013-11-09 14:19:19 +00:00
Evan Huus fa1027a004 From RobiOneKenobi via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9229
Add a new strutil function format_text_chr that replaces unprintable characters
with a single passed-in char (eg a '.' or a '-') instead of a C-style escape.
This is useful for displaying binary data that frequently but not always
contains text; otherwise the number of C escape codes makes it unreadable.

svn path=/trunk/; revision=52563
2013-10-12 12:38:56 +00:00
Michael Mann ee208c8dcc Add support for RELATIVE-OID ASN.1 type. Bug 9192 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9192)
From Ed Beroset.

svn path=/trunk/; revision=52393
2013-10-06 02:31:10 +00:00
Gerald Combs c0702583d3 Make the minimum supported GLib version 2.16.
svn path=/trunk/; revision=49444
2013-05-20 17:27:05 +00:00
Guy Harris 04c02451aa Add WS_DLL_PUBLIC to all functions declared here.
svn path=/trunk/; revision=49150
2013-05-03 23:37:06 +00:00
Evan Huus 63ef04ec84 Fix a whole bunch of doxygen warnings, mostly typos or renamed parameters.
svn path=/trunk/; revision=49053
2013-04-26 18:28:21 +00:00
Balint Reczey 1ebdb2e521 Export libwireshark symbols using WS_DLL_PUBLIC define
Also remove old WS_VAR_IMPORT define and related Makefile magic
everywhere in the project.

svn path=/trunk/; revision=47992
2013-03-01 23:53:11 +00:00
Bill Meier 96a24cc79f Fix spelling/typos found using a list of commonly misspelled words.
The misspellings were mostly in comments but some were
in text strings visible to the user.


svn path=/trunk/; revision=47899
2013-02-26 04:42:26 +00:00
Guy Harris 8ed7a73e22 Fix a bunch of warnings.
Cast away some implicit 64-bit-to-32-bit conversion errors due to use of
sizeof.

Cast away some implicit 64-bit-to-32-bit conversion errors due to use of
strtol() and strtoul().

Change some data types to avoid those implicit conversion warnings.

When assigning a constant to a float, make sure the constant isn't a
double, by appending "f" to the constant.

Constify a bunch of variables, parameters, and return values to
eliminate warnings due to strings being given const qualifiers.  Cast
away those warnings in some cases where an API we don't control forces
us to do so.

Enable a bunch of additional warnings by default.  Note why at least
some of the other warnings aren't enabled.

randpkt.c and text2pcap.c are used to build programs, so they don't need
to be in EXTRA_DIST.

If the user specifies --enable-warnings-as-errors, add -Werror *even if
the user specified --enable-extra-gcc-flags; assume they know what
they're doing and are willing to have the compile fail due to the extra
GCC warnings being treated as errors.

svn path=/trunk/; revision=46748
2012-12-26 05:57:06 +00:00
Anders Broman e9f13d771c g_strcmp0 first occures in GLIB 2.16 define it localy if it does not exist
to make builds on Fedora 8 with GTK 2.12 work.

svn path=/trunk/; revision=45707
2012-10-22 12:20:36 +00:00
Jakub Zawadzki bf81b42e1e Update Free Software Foundation address.
(COPYING will be updated in next commit)

svn path=/trunk/; revision=43536
2012-06-28 22:56:06 +00:00
Gerald Combs 6b178bd415 Add 'extern "C"' wrappers and #include guards to various header files.
svn path=/trunk/; revision=40321
2011-12-29 00:08:47 +00:00
Stephen Fisher 9246c41703 Change ws_strdup_escape_underscore() function to be more general, by
accepting any character as the escaped character.  Change existing
uses to use '_' for the underscore escaping.


svn path=/trunk/; revision=36627
2011-04-13 16:56:24 +00:00
Anders Broman a009cc0605 Doxygen changes.
svn path=/trunk/; revision=33990
2010-08-29 10:47:38 +00:00
Gerald Combs fa5f6cced7 From Edgar Gladkich:
This is an extension to the Wireshark context sensitive protocol help. Rows in
TreeView window are analyzed and suitable help file (as HTML) is opened in a
browser.

The help part (large file, 23 MB) of the Protocol Help can be downloaded under
www.inacon.com/dowload/stuff/protocol_help.tar.gz

This protocol help "light" provides descriptive content for the most frequently
used standard protocols, including IP, TCP or SMTP.

From me:

Changes:

Rename "ph_" in some function names to "proto_help_". Move the protocol
help code to its own module.

Make a bunch of functions static. Remove unused code.

Use browser_open_url() instead of a custom function.

Increase the logging levels. Don't clobber the normal log handler.

Update some Doxygen comments to match the format in the rest of the code
base.

Removed GTK version checks. We've been 2.x only for a while.

Move ph_replace_string to string_replace() in epan/strutil.[ch].

Fix a bunch of memory leaks.

Add a NULL pointer check.

Reformat the overview menu label.

Document the file format and locations.

Add Edgar to AUTHORS.

svn path=/trunk/; revision=32995
2010-05-27 15:51:25 +00:00
Gerasimos Dimitriadis c08fa6f3cf Move underscore escaping/unscaping function to strutil.c;
Update decoding of IS-801 Request GPS Acquisition Assistance

svn path=/trunk/; revision=31685
2010-01-26 18:21:17 +00:00
Anders Broman f82442badc Move IA5_7BIT_decode to strutil.c
svn path=/trunk/; revision=30669
2009-10-23 01:56:09 +00:00