aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2004-06-06 14:29:07 +0000
committerGerald Combs <gerald@wireshark.org>2004-06-06 14:29:07 +0000
commit4a0a8b7e72424ee27fbbb0aa534eff64b59bff9b (patch)
treed8dd0933717ff6071c0baa6c4cbdd3b8479af42c /epan
parentd9c70dcdf6999ebea7380f8202aab4ee746517b8 (diff)
Add a "force_separators" parameter to hex_str_to_bytes so that it's
possible to paste in WEP keys without any separators. Add doxygen comments to strutil.h. svn path=/trunk/; revision=11123
Diffstat (limited to 'epan')
-rw-r--r--epan/ftypes/ftype-bytes.c4
-rw-r--r--epan/strutil.c12
-rw-r--r--epan/strutil.h89
3 files changed, 92 insertions, 13 deletions
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c
index 8110f23c0f..b1dddb073c 100644
--- a/epan/ftypes/ftype-bytes.c
+++ b/epan/ftypes/ftype-bytes.c
@@ -1,5 +1,5 @@
/*
- * $Id: ftype-bytes.c,v 1.25 2004/02/27 12:00:31 obiot Exp $
+ * $Id: ftype-bytes.c,v 1.26 2004/06/06 14:29:07 gerald Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -160,7 +160,7 @@ bytes_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, Log
bytes = g_byte_array_new();
- res = hex_str_to_bytes(s, bytes);
+ res = hex_str_to_bytes(s, bytes, TRUE);
if (!res) {
if (logfunc != NULL)
diff --git a/epan/strutil.c b/epan/strutil.c
index df4dade4d5..b2b72457b7 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -1,7 +1,7 @@
/* strutil.c
* String utility routines
*
- * $Id: strutil.c,v 1.20 2004/05/01 23:56:03 guy Exp $
+ * $Id: strutil.c,v 1.21 2004/06/06 14:29:07 gerald Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -316,7 +316,7 @@ is_byte_sep(guint8 c)
* is_byte_sep() into a byte array.
*/
gboolean
-hex_str_to_bytes(const char *hex_str, GByteArray *bytes) {
+hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separators) {
guint8 val;
const guchar *p, *q, *punct;
char two_digits[3];
@@ -351,15 +351,13 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes) {
p = punct + 1;
continue;
}
- else {
+ else if (force_separators) {
return FALSE;
break;
}
}
- else {
- p = punct;
- continue;
- }
+ p = punct;
+ continue;
}
else if (*q && isxdigit(*p) && is_byte_sep(*q)) {
one_digit[0] = *p;
diff --git a/epan/strutil.h b/epan/strutil.h
index f78b5a7c0e..4f4e8bcca9 100644
--- a/epan/strutil.h
+++ b/epan/strutil.h
@@ -1,7 +1,7 @@
/* strutil.h
* String utility definitions
*
- * $Id: strutil.h,v 1.15 2004/05/01 20:46:24 obiot Exp $
+ * $Id: strutil.h,v 1.16 2004/06/06 14:29:07 gerald Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -27,16 +27,97 @@
/* ... thus, config.h needs to be #included */
+/** @file
+ * String handling and conversion utilities.
+ */
+
+/** Given a pointer into a data buffer, and to the end of the buffer,
+ * find the end of the (putative) line at that position in the data
+ * buffer.
+ *
+ * @param data A pointer to the beginning of the data
+ * @param dataend A pointer to the end of the data
+ * @param eol A pointer that will receive the EOL location
+ * @return A pointer to the EOL character(s) in "*eol".
+ */
const guchar *find_line_end(const guchar *data, const guchar *dataend,
const guchar **eol);
+
+/** Get the length of the next token in a line, and the beginning of the
+ * next token after that (if any).
+ * @param linep A pointer to the beginning of the line
+ * @param lineend A pointer to the end of the line
+ * @param next_token Receives the location of the next token
+ * @return 0 if there is no next token.
+ */
int get_token_len(const guchar *linep, const guchar *lineend,
const guchar **next_token);
+
+/** Given a string, generate a string from it that shows non-printable
+ * characters as C-style escapes, and return a pointer to it.
+ *
+ * @param line A pointer to the input string
+ * @param len The length of the input string
+ * @return A pointer to the formatted string
+ *
+ * @see tvb_format_text()
+ */
gchar* format_text(const guchar *line, int len);
-gchar* bytes_to_str(const guint8 *, int);
-gchar* bytes_to_str_punct(const guint8 *, int, gchar punct);
-gboolean hex_str_to_bytes(const char *hex_str, GByteArray *bytes);
+
+/** Turn an array of bytes into a string showing the bytes in hex.
+ *
+ * @param bd A pointer to the byte array
+ * @param bd_len The length of the byte array
+ * @return A pointer to the formatted string
+ *
+ * @see bytes_to_str_punct()
+ */
+gchar* bytes_to_str(const guint8 *bd, int bd_len);
+
+/** Turn an array of bytes into a string showing the bytes in hex,
+ * separated by a punctuation character.
+ *
+ * @param bd A pointer to the byte array
+ * @param bd_len The length of the byte array
+ * @param punct The punctuation character
+ * @return A pointer to the formatted string
+ *
+ * @see bytes_to_str()
+ */
+gchar* bytes_to_str_punct(const guint8 *bd, int bd_len, gchar punct);
+
+/** Turn a string of hex digits with optional separators (defined by
+ * is_byte_sep() into a byte array.
+ *
+ * @param hex_str The string of hex digits.
+ * @param bytes The GByteArray that will receive the bytes. This
+ * must be initialized by the caller.
+ * @param force_separators If set to TRUE, separators MUST exist between
+ * bytes.
+ * @return True if the string was converted successfully
+ */
+gboolean hex_str_to_bytes(const char *hex_str, GByteArray *bytes,
+ gboolean force_separators);
+
+/** Return a XML escaped representation of the unescaped string.
+ * The returned string must be freed when no longer in use.
+ *
+ * @param unescaped The unescaped string
+ * @return An XML-escaped representation of the input string
+ */
gchar* xml_escape(const gchar *unescaped);
+/* Return the first occurrence of needle in haystack.
+ * Algorithm copied from GNU's glibc 2.3.2 memcmp()
+ *
+ * @param haystack The data to search
+ * @param haystack_len The length of the search data
+ * @param needle The string to look for
+ * @param needle_len The length of the search string
+ * @return A pointer to the first occurrence of "needle" in
+ * "haystack". If "needle" isn't found or is NULL, or if
+ * "needle_len" is 0, NULL is returned.
+ */
const guint8 * epan_memmem(const guint8 *haystack, guint haystack_len,
const guint8 *needle, guint needle_len);