aboutsummaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2008-06-11 08:45:09 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2008-06-11 08:45:09 +0000
commit90efcacba6378a4e29275cd6e9914d73d836a4a4 (patch)
treeda032ba71582994f9e1f2ed7162ba14f152cb7d7 /buffer.c
parentAdded support for building and linking with (diff)
downloadopenvpn-90efcacba6378a4e29275cd6e9914d73d836a4a4.tar.xz
Updated version to 2.1_rc7e.
Added client authentication and packet filtering capability to management interface. Extended packet filtering capability to work on both --dev tun and --dev tap tunnels. Updated valgrind-suppress file. Made "Linux ip addr del failed" error nonfatal. Amplified --client-cert-not-required warning. Added #pragma pack to proto.h. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@2991 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index 6ceaacf..92b10e5 100644
--- a/buffer.c
+++ b/buffer.c
@@ -819,3 +819,130 @@ valign4 (const struct buffer *buf, const char *file, const int line)
}
}
#endif
+
+/*
+ * struct buffer_list
+ */
+
+#ifdef ENABLE_BUFFER_LIST
+
+struct buffer_list *
+buffer_list_new (const int max_size)
+{
+ struct buffer_list *ret;
+ ALLOC_OBJ_CLEAR (ret, struct buffer_list);
+ ret->max_size = max_size;
+ ret->size = 0;
+ return ret;
+}
+
+void
+buffer_list_free (struct buffer_list *ol)
+{
+ buffer_list_reset (ol);
+ free (ol);
+}
+
+bool
+buffer_list_defined (const struct buffer_list *ol)
+{
+ return ol->head != NULL;
+}
+
+void
+buffer_list_reset (struct buffer_list *ol)
+{
+ struct buffer_entry *e = ol->head;
+ while (e)
+ {
+ struct buffer_entry *next = e->next;
+ free_buf (&e->buf);
+ free (e);
+ e = next;
+ }
+ ol->head = ol->tail = NULL;
+ ol->size = 0;
+}
+
+void
+buffer_list_push (struct buffer_list *ol, const unsigned char *str)
+{
+ if (!ol->max_size || ol->size < ol->max_size)
+ {
+ struct buffer_entry *e;
+ ALLOC_OBJ_CLEAR (e, struct buffer_entry);
+
+ ++ol->size;
+ if (ol->tail)
+ {
+ ASSERT (ol->head);
+ ol->tail->next = e;
+ }
+ else
+ {
+ ASSERT (!ol->head);
+ ol->head = e;
+ }
+ e->buf = string_alloc_buf ((const char *) str, NULL);
+ ol->tail = e;
+ }
+}
+
+const struct buffer *
+buffer_list_peek (struct buffer_list *ol)
+{
+ if (ol->head)
+ return &ol->head->buf;
+ else
+ return NULL;
+}
+
+static void
+buffer_list_pop (struct buffer_list *ol)
+{
+ if (ol->head)
+ {
+ struct buffer_entry *e = ol->head->next;
+ free_buf (&ol->head->buf);
+ free (ol->head);
+ ol->head = e;
+ --ol->size;
+ if (!e)
+ ol->tail = NULL;
+ }
+}
+
+void
+buffer_list_advance (struct buffer_list *ol, int n)
+{
+ if (ol->head)
+ {
+ struct buffer *buf = &ol->head->buf;
+ ASSERT (buf_advance (buf, n));
+ if (!BLEN (buf))
+ buffer_list_pop (ol);
+ }
+}
+
+struct buffer_list *
+buffer_list_file (const char *fn, int max_line_len)
+{
+ FILE *fp = fopen (fn, "r");
+ struct buffer_list *bl = NULL;
+
+ if (fp)
+ {
+ char *line = (char *) malloc (max_line_len);
+ if (line)
+ {
+ bl = buffer_list_new (0);
+ while (fgets (line, max_line_len, fp) != NULL)
+ buffer_list_push (bl, (unsigned char *)line);
+ free (line);
+ }
+ fclose (fp);
+ }
+ return bl;
+}
+
+#endif