Introduce two new functions:
authorsfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 27 Mar 2009 19:40:23 +0000 (19:40 +0000)
committersfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 27 Mar 2009 19:40:23 +0000 (19:40 +0000)
  tvb_get_seasonal_string();
  tvb_get_seasonal_stringz();

.. which work the same as the ephemeral versions of the functions, but use
se_alloc() instead of ep_alloc().

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@27868 f5534014-38df-0310-8fa8-9805f1628bb7

doc/README.developer
epan/tvbuff.c
epan/tvbuff.h

index 7ce7b1517598247407b6db4251df7220dc960ae1..be0279452ee563ecf14524706c0fbb035dcfd48c 100644 (file)
@@ -1127,6 +1127,7 @@ String accessors:
 
 guint8 *tvb_get_string(tvbuff_t*, gint offset, gint length);
 guint8 *tvb_get_ephemeral_string(tvbuff_t*, gint offset, gint length);
+guint8 *tvb_get_seasonal_string(tvbuff_t*, gint offset, gint length);
 
 Returns a null-terminated buffer containing data from the specified
 tvbuff, starting at the specified offset, and containing the specified
@@ -1136,14 +1137,20 @@ as it includes a null character to terminate the string).
 tvb_get_string() returns a buffer allocated by g_malloc() so you must
 g_free() it when you are finished with the string. Failure to g_free() this
 buffer will lead to memory leaks.
+
 tvb_get_ephemeral_string() returns a buffer allocated from a special heap
 with a lifetime until the next packet is dissected. You do not need to
 free() this buffer, it will happen automatically once the next packet is
 dissected.
 
+tvb_get_seasonal_string() returns a buffer allocated from a special heap
+with a lifetime of the current capture session. You do not need to
+free() this buffer, it will happen automatically once the a new capture or
+file is opened.
 
 guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
 guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
+guint8 *tvb_get_seasonal_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
 
 Returns a null-terminated buffer, allocated with "g_malloc()",
 containing data from the specified tvbuff, starting at the
@@ -1159,6 +1166,10 @@ with a lifetime until the next packet is dissected. You do not need to
 free() this buffer, it will happen automatically once the next packet is
 dissected.
 
+tvb_get_seasonal_stringz() returns a buffer allocated from a special heap
+with a lifetime of the current capture session. You do not need to
+free() this buffer, it will happen automatically once the a new capture or
+file is opened.
 
 guint8 *tvb_fake_unicode(tvbuff_t*, gint offset, gint length, gboolean little_endian);
 guint8 *tvb_get_ephemeral_faked_unicode(tvbuff_t*, gint offset, gint length, gboolean little_endian);
index a47d7792e634c69db43e9c3e590ed5212109dcea..c3d4fb6c58e8435ebcc896688df8f0deb01ba5df 100644 (file)
@@ -2144,6 +2144,34 @@ tvb_get_ephemeral_string(tvbuff_t *tvb, gint offset, gint length)
        return strbuf;
 }
 
+/*
+ * Given a tvbuff, an offset, and a length, allocate a buffer big enough
+ * to hold a non-null-terminated string of that length at that offset,
+ * plus a trailing '\0', copy the string into it, and return a pointer
+ * to the string.
+ *
+ * Throws an exception if the tvbuff ends before the string does.
+ *
+ * This function allocates memory from a buffer with capture session lifetime.
+ * You do not have to free this buffer, it will be automatically freed
+ * when wireshark starts or opens a new capture.
+ */
+guint8 *
+tvb_get_seasonal_string(tvbuff_t *tvb, gint offset, gint length)
+{
+       const guint8 *ptr;
+       guint8 *strbuf = NULL;
+
+       tvb_ensure_bytes_exist(tvb, offset, length);
+
+       ptr = ensure_contiguous(tvb, offset, length);
+       strbuf = se_alloc(length + 1);
+       if (length != 0) {
+               memcpy(strbuf, ptr, length);
+       }
+       strbuf[length] = '\0';
+       return strbuf;
+}
 
 /*
  * Given a tvbuff and an offset, with the offset assumed to refer to
@@ -2192,6 +2220,31 @@ tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp)
        return strptr;
 }
 
+/*
+ * Given a tvbuff and an offset, with the offset assumed to refer to
+ * a null-terminated string, find the length of that string (and throw
+ * an exception if the tvbuff ends before we find the null), allocate
+ * a buffer big enough to hold the string, copy the string into it,
+ * and return a pointer to the string.  Also return the length of the
+ * string (including the terminating null) through a pointer.
+ *
+ * This function allocates memory from a buffer with capture session lifetime.
+ * You do not have to free this buffer, it will be automatically freed
+ * when wireshark starts or opens a new capture.
+ */
+guint8 *
+tvb_get_seasonal_stringz(tvbuff_t *tvb, gint offset, gint *lengthp)
+{
+       guint size;
+       guint8 *strptr;
+
+       size = tvb_strsize(tvb, offset);
+       strptr = se_alloc(size);
+       tvb_memcpy(tvb, strptr, offset, size);
+       *lengthp = size;
+       return strptr;
+}
+
 /* Looks for a stringz (NUL-terminated string) in tvbuff and copies
  * no more than bufsize number of bytes, including terminating NUL, to buffer.
  * Returns length of string (not including terminating NUL), or -1 if the string was
index 7ddf58db72624d24f9bcb502272d43dc53b33ef7..84c4c9cbe6496fbdce1c9d2556860a6062f0d8fd 100644 (file)
@@ -460,9 +460,14 @@ extern gchar *tvb_format_stringzpad(tvbuff_t *tvb, gint offset, gint size);
  * tvb_get_ephemeral_string() returns a string that does not need to be freed,
  *                   instead it will automatically be freed once the next
  *                   packet is dissected.
+ *
+ * tvb_get_seasonal_string() returns a string that does not need to be freed,
+ *                   instead it will automatically be freed when a new capture
+ *                   or file is opened.
  */
 extern guint8 *tvb_get_string(tvbuff_t *tvb, gint offset, gint length);
 extern guint8 *tvb_get_ephemeral_string(tvbuff_t *tvb, gint offset, gint length);
+extern guint8 *tvb_get_seasonal_string(tvbuff_t *tvb, gint offset, gint length);
 
 
 /**
@@ -480,9 +485,14 @@ extern guint8 *tvb_get_ephemeral_string(tvbuff_t *tvb, gint offset, gint length)
  * tvb_get_ephemeral_stringz() returns a string that does not need to be freed,
  *                   instead it will automatically be freed once the next
  *                   packet is dissected.
+ *
+ * tvb_get_seasonal_stringz() returns a string that does not need to be freed,
+ *                   instead it will automatically be freed when a new capture
+ *                   or file is opened.
  */
 extern guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
 extern guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
+extern guint8 *tvb_get_seasonal_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
 
 /** Looks for a stringz (NUL-terminated string) in tvbuff and copies
  * no more than bufsize number of bytes, including terminating NUL, to buffer.