]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add stream_set_endp()
authorSubbaiah Venkata <svenkata@google.com>
Sat, 24 Mar 2012 20:10:19 +0000 (13:10 -0700)
committerAvneesh Sachdev <avneesh@opensourcerouting.org>
Sat, 7 Apr 2012 20:53:40 +0000 (13:53 -0700)
  * lib/stream.[ch]:

    - Add stream_set_endp(). This can be used to trim data (for
      example, padding) at the end of a stream.

    - Fix swapped 'getp' and 'endp' parameters in STREAM_WARN_OFFSETS.

From: Subbaiah Venkata <svenkata@google.com>
Signed-off-by: Avneesh Sachdev <avneesh@opensourcerouting.org>
Signed-off-by: David Lamparter <equinox@diac24.net>
lib/stream.c
lib/stream.h

index 983330ffb4a3b19ac0a6e7a668aebe76b953f197..b226a25ea544ad8601979b8cfd9a35b2dbf77ae9 100644 (file)
@@ -52,7 +52,7 @@
  * using stream_put..._at() functions.
  */
 #define STREAM_WARN_OFFSETS(S) \
-  zlog_warn ("&(struct stream): %p, size: %lu, endp: %lu, getp: %lu\n", \
+  zlog_warn ("&(struct stream): %p, size: %lu, getp: %lu, endp: %lu\n", \
              (S), \
              (unsigned long) (S)->size, \
              (unsigned long) (S)->getp, \
@@ -214,6 +214,20 @@ stream_set_getp (struct stream *s, size_t pos)
   s->getp = pos;
 }
 
+void
+stream_set_endp (struct stream *s, size_t pos)
+{
+  STREAM_VERIFY_SANE(s);
+
+  if (!GETP_VALID (s, pos))
+    {
+      STREAM_BOUND_WARN (s, "set endp");
+      pos = s->endp;
+    }
+
+  s->endp = pos;
+}
+
 /* Forward pointer. */
 void
 stream_forward_getp (struct stream *s, size_t size)
@@ -934,9 +948,9 @@ stream_fifo_pop (struct stream_fifo *fifo)
 
       if (fifo->head == NULL)
        fifo->tail = NULL;
-    }
 
-  fifo->count--;
+      fifo->count--;
+    }
 
   return s; 
 }
index 3e4ba7b41af27abc8ebbabfde0c15de162efa217..f10aa6d417125ea8ac77448b5e2ad2f836b6f402 100644 (file)
@@ -146,6 +146,7 @@ extern size_t stream_get_size (struct stream *);
 extern u_char *stream_get_data (struct stream *);
 
 extern void stream_set_getp (struct stream *, size_t);
+extern void stream_set_endp (struct stream *, size_t);
 extern void stream_forward_getp (struct stream *, size_t);
 extern void stream_forward_endp (struct stream *, size_t);