[master] dddb171ba vte: Beginning of an incremental API

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 21 20:52:06 UTC 2023


commit dddb171babbffa918dca0d2c7075953b15b73842
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Aug 17 08:29:40 2023 +0200

    vte: Beginning of an incremental API

diff --git a/include/Makefile.am b/include/Makefile.am
index 0fa196b39..1a68ab4a3 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -80,6 +80,7 @@ nobase_pkginclude_HEADERS += \
 	vsb.h \
 	vsha256.h \
 	vtcp.h \
+	vte.h \
 	vtim.h \
 	vtree.h \
 	vrnd.h
diff --git a/include/vte.h b/include/vte.h
new file mode 100644
index 000000000..e15d4c233
--- /dev/null
+++ b/include/vte.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2023 Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer
+ *    in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+struct vte;
+
+struct vte *VTE_new(int maxfields, int width);
+void VTE_destroy(struct vte **);
diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c
index 953975333..1d915a42d 100644
--- a/lib/libvarnish/vte.c
+++ b/lib/libvarnish/vte.c
@@ -37,13 +37,60 @@
 
 #include "vdef.h"
 #include "vqueue.h"
+#include "miniobj.h"
 
 #include "vas.h"
 #include "vcli_serve.h"
 #include "vsb.h"
+#include "vte.h"
 
 #define MAXCOL 10
 
+struct vte {
+	unsigned	magic;
+#define VTE_MAGIC	0xedf42b97
+	struct vsb	*vsb;
+	int		c_off;		/* input char offset */
+	int		l_sz;		/* input line size */
+	int		l_maxsz;	/* maximum input line size */
+	int		o_sz;		/* output sz */
+	int		o_sep;		/* output field separators */
+	int		f_off;		/* input field offset */
+	int		f_sz;		/* input field size */
+	int		f_cnt;		/* actual number of fields */
+	int		f_maxcnt;	/* maximum number of fields */
+	int		f_maxsz[];	/* maximum size per field */
+};
+
+struct vte *
+VTE_new(int maxfields, int width)
+{
+	struct vte *vte;
+
+	assert(maxfields > 0);
+	assert(width > 0);
+
+	ALLOC_FLEX_OBJ(vte, f_maxsz, maxfields, VTE_MAGIC);
+	if (vte != NULL) {
+		vte->o_sz = width;
+		vte->f_maxcnt = maxfields;
+		vte->vsb = VSB_new_auto();
+		AN(vte->vsb);
+	}
+	return (vte);
+}
+
+void
+VTE_destroy(struct vte **vtep)
+{
+	struct vte *vte;
+
+	TAKE_OBJ_NOTNULL(vte, vtep, VTE_MAGIC);
+	AN(vte->vsb);
+	VSB_destroy(&vte->vsb);
+	FREE_OBJ(vte);
+}
+
 void
 VCLI_VTE(struct cli *cli, struct vsb **src, int width)
 {


More information about the varnish-commit mailing list