r4934 - trunk/varnish-cache/lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Tue Jun 8 12:19:34 CEST 2010
Author: phk
Date: 2010-06-08 12:19:34 +0200 (Tue, 08 Jun 2010)
New Revision: 4934
Added:
trunk/varnish-cache/lib/libvarnishapi/vsc.c
trunk/varnish-cache/lib/libvarnishapi/vsl.c
Removed:
trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
Modified:
trunk/varnish-cache/lib/libvarnishapi/Makefile.am
Log:
rename files to match subject matter
Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 10:15:00 UTC (rev 4933)
+++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 10:19:34 UTC (rev 4934)
@@ -19,8 +19,8 @@
base64.c \
vsm.c \
vsl_arg.c \
- vsl_log.c \
- vsl_stat.c
+ vsl.c \
+ vsc.c
libvarnishapi_la_CFLAGS = \
-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
Copied: trunk/varnish-cache/lib/libvarnishapi/vsc.c (from rev 4933, trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c)
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsc.c (rev 0)
+++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 10:19:34 UTC (rev 4934)
@@ -0,0 +1,176 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2010 Redpill Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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.
+ * 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 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.
+ */
+
+#include "config.h"
+
+#include "svnid.h"
+SVNID("$Id$")
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+
+#include "vas.h"
+#include "vsm.h"
+#include "vsc.h"
+#include "vre.h"
+#include "vqueue.h"
+#include "miniobj.h"
+#include "varnishapi.h"
+
+#include "vslapi.h"
+
+/*--------------------------------------------------------------------*/
+
+struct vsc_main *
+VSM_OpenStats(struct VSM_data *vd)
+{
+ struct vsm_chunk *sha;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+
+ sha = vsm_find_alloc(vd, VSC_CLASS, "", "");
+ assert(sha != NULL);
+ return (VSM_PTR(sha));
+}
+
+/*--------------------------------------------------------------------
+ * -1 -> unknown stats encountered.
+ */
+
+static inline int
+iter_test(const char *s1, const char *s2, int wc)
+{
+
+ if (s1 == NULL)
+ return (0);
+ if (!wc)
+ return (strcmp(s1, s2));
+ for (; *s1 != '\0' && *s1 == *s2; s1++, s2++)
+ continue;
+ return (*s1 != '\0');
+}
+
+static int
+iter_call(const struct VSM_data *vd, vsl_stat_f *func, void *priv,
+ const struct vsl_statpt *const sp)
+{
+ struct vsl_sf *sf;
+ int good = vd->sf_init;
+
+ if (VTAILQ_EMPTY(&vd->sf_list))
+ return (func(priv, sp));
+
+ VTAILQ_FOREACH(sf, &vd->sf_list, next) {
+ if (iter_test(sf->class, sp->class, sf->flags & VSL_SF_CL_WC))
+ continue;
+ if (iter_test(sf->ident, sp->ident, sf->flags & VSL_SF_ID_WC))
+ continue;
+ if (iter_test(sf->name, sp->name, sf->flags & VSL_SF_NM_WC))
+ continue;
+ if (sf->flags & VSL_SF_EXCL)
+ good = 0;
+ else
+ good = 1;
+ }
+ if (!good)
+ return (0);
+ return (func(priv, sp));
+}
+
+static int
+iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
+ void *priv)
+{
+ struct vsc_main *st = VSM_PTR(sha);
+ struct vsl_statpt sp;
+ int i;
+
+ sp.class = "";
+ sp.ident = "";
+#define VSC_F_MAIN(nn, tt, ll, ff, dd) \
+ sp.name = #nn; \
+ sp.fmt = #tt; \
+ sp.flag = ff; \
+ sp.desc = dd; \
+ sp.ptr = &st->nn; \
+ i = iter_call(vd, func, priv, &sp); \
+ if (i) \
+ return(i);
+#include "vsc_fields.h"
+#undef VSC_F_MAIN
+ return (0);
+}
+
+static int
+iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
+ void *priv)
+{
+ struct vsc_sma *st = VSM_PTR(sha);
+ struct vsl_statpt sp;
+ int i;
+
+ sp.class = VSC_TYPE_SMA;
+ sp.ident = sha->ident;
+#define VSC_F_SMA(nn, tt, ll, ff, dd) \
+ sp.name = #nn; \
+ sp.fmt = #tt; \
+ sp.flag = ff; \
+ sp.desc = dd; \
+ sp.ptr = &st->nn; \
+ i = iter_call(vd, func, priv, &sp); \
+ if (i) \
+ return(i);
+#include "vsc_fields.h"
+#undef VSC_F_SMA
+ return (0);
+}
+
+int
+VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv)
+{
+ struct vsm_chunk *sha;
+ int i;
+
+ i = 0;
+ VSM_FOREACH(sha, vd) {
+ CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+ if (strcmp(sha->class, VSC_CLASS))
+ continue;
+ if (!strcmp(sha->type, VSC_TYPE_MAIN))
+ i = iter_main(vd, sha, func, priv);
+ else if (!strcmp(sha->type, VSC_TYPE_SMA))
+ i = iter_sma(vd, sha, func, priv);
+ else
+ i = -1;
+ if (i != 0)
+ break;
+ }
+ return (i);
+}
Copied: trunk/varnish-cache/lib/libvarnishapi/vsl.c (from rev 4933, trunk/varnish-cache/lib/libvarnishapi/vsl_log.c)
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c (rev 0)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 10:19:34 UTC (rev 4934)
@@ -0,0 +1,282 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2010 Redpill Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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.
+ * 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 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.
+ */
+
+#include "config.h"
+
+#include "svnid.h"
+SVNID("$Id$")
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "vas.h"
+#include "vsm.h"
+#include "vsl.h"
+#include "vre.h"
+#include "vbm.h"
+#include "vqueue.h"
+#include "miniobj.h"
+#include "varnishapi.h"
+
+#include "vslapi.h"
+#include "vmb.h"
+
+static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp);
+
+/*--------------------------------------------------------------------*/
+
+const char *VSL_tags[256] = {
+#define SLTM(foo) [SLT_##foo] = #foo,
+#include "vsl_tags.h"
+#undef SLTM
+};
+
+/*--------------------------------------------------------------------*/
+
+void
+VSL_Select(const struct VSM_data *vd, unsigned tag)
+{
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ vbit_set(vd->vbm_select, tag);
+}
+
+
+/*--------------------------------------------------------------------*/
+
+void
+VSL_NonBlocking(struct VSM_data *vd, int nb)
+{
+ if (nb)
+ vd->flags |= F_NON_BLOCKING;
+ else
+ vd->flags &= ~F_NON_BLOCKING;
+}
+
+/*--------------------------------------------------------------------*/
+
+static int
+vsl_nextlog(struct VSM_data *vd, uint32_t **pp)
+{
+ unsigned w, l;
+ uint32_t t;
+ int i;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ if (vd->r_fd != -1) {
+ assert(vd->rbuflen >= 8);
+ i = read(vd->r_fd, vd->rbuf, 8);
+ if (i != 8)
+ return (-1);
+ l = 2 + VSL_WORDS(VSL_LEN(vd->rbuf));
+ if (vd->rbuflen < l) {
+ l += 256;
+ vd->rbuf = realloc(vd->rbuf, l * 4);
+ assert(vd->rbuf != NULL);
+ vd->rbuflen = l;
+ }
+ i = read(vd->r_fd, vd->rbuf + 2, l * 4 - 8);
+ if (i != l)
+ return (-1);
+ *pp = vd->rbuf;
+ return (1);
+ }
+ for (w = 0; w < TIMEOUT_USEC;) {
+ t = *vd->log_ptr;
+
+ if (t == VSL_WRAPMARKER ||
+ (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) {
+ vd->log_ptr = vd->log_start + 1;
+ vd->last_seq = vd->log_start[0];
+ VRMB();
+ continue;
+ }
+ if (t == VSL_ENDMARKER) {
+ if (vd->flags & F_NON_BLOCKING)
+ return (-1);
+ w += SLEEP_USEC;
+ AZ(usleep(SLEEP_USEC));
+ continue;
+ }
+ *pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */
+ vd->log_ptr = VSL_NEXT(vd->log_ptr);
+ return (1);
+ }
+ *pp = NULL;
+ return (0);
+}
+
+int
+VSL_NextLog(struct VSM_data *vd, uint32_t **pp)
+{
+ uint32_t *p;
+ unsigned char t;
+ unsigned u;
+ int i;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ while (1) {
+ i = vsl_nextlog(vd, &p);
+ if (i != 1)
+ return (i);
+ u = VSL_ID(p);
+ t = VSL_TAG(p);
+ switch(t) {
+ case SLT_SessionOpen:
+ case SLT_ReqStart:
+ vbit_set(vd->vbm_client, u);
+ vbit_clr(vd->vbm_backend, u);
+ break;
+ case SLT_BackendOpen:
+ case SLT_BackendXID:
+ vbit_clr(vd->vbm_client, u);
+ vbit_set(vd->vbm_backend, u);
+ break;
+ default:
+ break;
+ }
+ if (vd->skip) {
+ --vd->skip;
+ continue;
+ } else if (vd->keep) {
+ if (--vd->keep == 0)
+ return (-1);
+ }
+
+ if (vbit_test(vd->vbm_select, t)) {
+ *pp = p;
+ return (1);
+ }
+ if (vbit_test(vd->vbm_supress, t))
+ continue;
+ if (vd->b_opt && !vbit_test(vd->vbm_backend, u))
+ continue;
+ if (vd->c_opt && !vbit_test(vd->vbm_client, u))
+ continue;
+ if (vd->regincl != NULL) {
+ i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
+ 0, 0, NULL, 0);
+ if (i == VRE_ERROR_NOMATCH)
+ continue;
+ }
+ if (vd->regexcl != NULL) {
+ i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
+ 0, 0, NULL, 0);
+ if (i != VRE_ERROR_NOMATCH)
+ continue;
+ }
+ *pp = p;
+ return (1);
+ }
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv)
+{
+ int i;
+ unsigned u, l, s;
+ uint32_t *p;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ while (1) {
+ i = VSL_NextLog(vd, &p);
+ if (i != 1)
+ return (i);
+ u = VSL_ID(p);
+ l = VSL_LEN(p);
+ s = 0;
+ if (vbit_test(vd->vbm_backend, u))
+ s |= VSL_S_BACKEND;
+ if (vbit_test(vd->vbm_client, u))
+ s |= VSL_S_CLIENT;
+ if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p)))
+ return (1);
+ }
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VSL_H_Print(void *priv, enum vsl_tag tag, unsigned fd, unsigned len,
+ unsigned spec, const char *ptr)
+{
+ FILE *fo = priv;
+ int type;
+
+ assert(fo != NULL);
+
+ type = (spec & VSL_S_CLIENT) ? 'c' :
+ (spec & VSL_S_BACKEND) ? 'b' : '-';
+
+ if (tag == SLT_Debug) {
+ fprintf(fo, "%5u %-12s %c \"", fd, VSL_tags[tag], type);
+ while (len-- > 0) {
+ if (*ptr >= ' ' && *ptr <= '~')
+ fprintf(fo, "%c", *ptr);
+ else
+ fprintf(fo, "%%%02x", (unsigned char)*ptr);
+ ptr++;
+ }
+ fprintf(fo, "\"\n");
+ return (0);
+ }
+ fprintf(fo, "%5u %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr);
+ return (0);
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VSM_OpenLog(struct VSM_data *vd)
+{
+ struct vsm_chunk *sha;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ sha = vsm_find_alloc(vd, VSL_CLASS, "", "");
+ assert(sha != NULL);
+
+ vd->log_start = VSM_PTR(sha);
+ vd->log_end = VSM_NEXT(sha);
+ vd->log_ptr = vd->log_start + 1;
+
+ vd->last_seq = vd->log_start[0];
+ VRMB();
+ if (!vd->d_opt && vd->r_fd == -1) {
+ while (*vd->log_ptr != VSL_ENDMARKER)
+ vd->log_ptr = VSL_NEXT(vd->log_ptr);
+ }
+ return (0);
+}
Deleted: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 10:15:00 UTC (rev 4933)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 10:19:34 UTC (rev 4934)
@@ -1,282 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2010 Redpill Linpro AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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.
- * 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 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.
- */
-
-#include "config.h"
-
-#include "svnid.h"
-SVNID("$Id$")
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "vas.h"
-#include "vsm.h"
-#include "vsl.h"
-#include "vre.h"
-#include "vbm.h"
-#include "vqueue.h"
-#include "miniobj.h"
-#include "varnishapi.h"
-
-#include "vslapi.h"
-#include "vmb.h"
-
-static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp);
-
-/*--------------------------------------------------------------------*/
-
-const char *VSL_tags[256] = {
-#define SLTM(foo) [SLT_##foo] = #foo,
-#include "vsl_tags.h"
-#undef SLTM
-};
-
-/*--------------------------------------------------------------------*/
-
-void
-VSL_Select(const struct VSM_data *vd, unsigned tag)
-{
-
- CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
- vbit_set(vd->vbm_select, tag);
-}
-
-
-/*--------------------------------------------------------------------*/
-
-void
-VSL_NonBlocking(struct VSM_data *vd, int nb)
-{
- if (nb)
- vd->flags |= F_NON_BLOCKING;
- else
- vd->flags &= ~F_NON_BLOCKING;
-}
-
-/*--------------------------------------------------------------------*/
-
-static int
-vsl_nextlog(struct VSM_data *vd, uint32_t **pp)
-{
- unsigned w, l;
- uint32_t t;
- int i;
-
- CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
- if (vd->r_fd != -1) {
- assert(vd->rbuflen >= 8);
- i = read(vd->r_fd, vd->rbuf, 8);
- if (i != 8)
- return (-1);
- l = 2 + VSL_WORDS(VSL_LEN(vd->rbuf));
- if (vd->rbuflen < l) {
- l += 256;
- vd->rbuf = realloc(vd->rbuf, l * 4);
- assert(vd->rbuf != NULL);
- vd->rbuflen = l;
- }
- i = read(vd->r_fd, vd->rbuf + 2, l * 4 - 8);
- if (i != l)
- return (-1);
- *pp = vd->rbuf;
- return (1);
- }
- for (w = 0; w < TIMEOUT_USEC;) {
- t = *vd->log_ptr;
-
- if (t == VSL_WRAPMARKER ||
- (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) {
- vd->log_ptr = vd->log_start + 1;
- vd->last_seq = vd->log_start[0];
- VRMB();
- continue;
- }
- if (t == VSL_ENDMARKER) {
- if (vd->flags & F_NON_BLOCKING)
- return (-1);
- w += SLEEP_USEC;
- AZ(usleep(SLEEP_USEC));
- continue;
- }
- *pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */
- vd->log_ptr = VSL_NEXT(vd->log_ptr);
- return (1);
- }
- *pp = NULL;
- return (0);
-}
-
-int
-VSL_NextLog(struct VSM_data *vd, uint32_t **pp)
-{
- uint32_t *p;
- unsigned char t;
- unsigned u;
- int i;
-
- CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
- while (1) {
- i = vsl_nextlog(vd, &p);
- if (i != 1)
- return (i);
- u = VSL_ID(p);
- t = VSL_TAG(p);
- switch(t) {
- case SLT_SessionOpen:
- case SLT_ReqStart:
- vbit_set(vd->vbm_client, u);
- vbit_clr(vd->vbm_backend, u);
- break;
- case SLT_BackendOpen:
- case SLT_BackendXID:
- vbit_clr(vd->vbm_client, u);
- vbit_set(vd->vbm_backend, u);
- break;
- default:
- break;
- }
- if (vd->skip) {
- --vd->skip;
- continue;
- } else if (vd->keep) {
- if (--vd->keep == 0)
- return (-1);
- }
-
- if (vbit_test(vd->vbm_select, t)) {
- *pp = p;
- return (1);
- }
- if (vbit_test(vd->vbm_supress, t))
- continue;
- if (vd->b_opt && !vbit_test(vd->vbm_backend, u))
- continue;
- if (vd->c_opt && !vbit_test(vd->vbm_client, u))
- continue;
- if (vd->regincl != NULL) {
- i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
- 0, 0, NULL, 0);
- if (i == VRE_ERROR_NOMATCH)
- continue;
- }
- if (vd->regexcl != NULL) {
- i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
- 0, 0, NULL, 0);
- if (i != VRE_ERROR_NOMATCH)
- continue;
- }
- *pp = p;
- return (1);
- }
-}
-
-/*--------------------------------------------------------------------*/
-
-int
-VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv)
-{
- int i;
- unsigned u, l, s;
- uint32_t *p;
-
- CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
- while (1) {
- i = VSL_NextLog(vd, &p);
- if (i != 1)
- return (i);
- u = VSL_ID(p);
- l = VSL_LEN(p);
- s = 0;
- if (vbit_test(vd->vbm_backend, u))
- s |= VSL_S_BACKEND;
- if (vbit_test(vd->vbm_client, u))
- s |= VSL_S_CLIENT;
- if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p)))
- return (1);
- }
-}
-
-/*--------------------------------------------------------------------*/
-
-int
-VSL_H_Print(void *priv, enum vsl_tag tag, unsigned fd, unsigned len,
- unsigned spec, const char *ptr)
-{
- FILE *fo = priv;
- int type;
-
- assert(fo != NULL);
-
- type = (spec & VSL_S_CLIENT) ? 'c' :
- (spec & VSL_S_BACKEND) ? 'b' : '-';
-
- if (tag == SLT_Debug) {
- fprintf(fo, "%5u %-12s %c \"", fd, VSL_tags[tag], type);
- while (len-- > 0) {
- if (*ptr >= ' ' && *ptr <= '~')
- fprintf(fo, "%c", *ptr);
- else
- fprintf(fo, "%%%02x", (unsigned char)*ptr);
- ptr++;
- }
- fprintf(fo, "\"\n");
- return (0);
- }
- fprintf(fo, "%5u %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr);
- return (0);
-}
-
-/*--------------------------------------------------------------------*/
-
-int
-VSM_OpenLog(struct VSM_data *vd)
-{
- struct vsm_chunk *sha;
-
- CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
- sha = vsm_find_alloc(vd, VSL_CLASS, "", "");
- assert(sha != NULL);
-
- vd->log_start = VSM_PTR(sha);
- vd->log_end = VSM_NEXT(sha);
- vd->log_ptr = vd->log_start + 1;
-
- vd->last_seq = vd->log_start[0];
- VRMB();
- if (!vd->d_opt && vd->r_fd == -1) {
- while (*vd->log_ptr != VSL_ENDMARKER)
- vd->log_ptr = VSL_NEXT(vd->log_ptr);
- }
- return (0);
-}
Deleted: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 10:15:00 UTC (rev 4933)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 10:19:34 UTC (rev 4934)
@@ -1,176 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2010 Redpill Linpro AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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.
- * 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 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.
- */
-
-#include "config.h"
-
-#include "svnid.h"
-SVNID("$Id$")
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-
-#include "vas.h"
-#include "vsm.h"
-#include "vsc.h"
-#include "vre.h"
-#include "vqueue.h"
-#include "miniobj.h"
-#include "varnishapi.h"
-
-#include "vslapi.h"
-
-/*--------------------------------------------------------------------*/
-
-struct vsc_main *
-VSM_OpenStats(struct VSM_data *vd)
-{
- struct vsm_chunk *sha;
-
- CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
-
- sha = vsm_find_alloc(vd, VSC_CLASS, "", "");
- assert(sha != NULL);
- return (VSM_PTR(sha));
-}
-
-/*--------------------------------------------------------------------
- * -1 -> unknown stats encountered.
- */
-
-static inline int
-iter_test(const char *s1, const char *s2, int wc)
-{
-
- if (s1 == NULL)
- return (0);
- if (!wc)
- return (strcmp(s1, s2));
- for (; *s1 != '\0' && *s1 == *s2; s1++, s2++)
- continue;
- return (*s1 != '\0');
-}
-
-static int
-iter_call(const struct VSM_data *vd, vsl_stat_f *func, void *priv,
- const struct vsl_statpt *const sp)
-{
- struct vsl_sf *sf;
- int good = vd->sf_init;
-
- if (VTAILQ_EMPTY(&vd->sf_list))
- return (func(priv, sp));
-
- VTAILQ_FOREACH(sf, &vd->sf_list, next) {
- if (iter_test(sf->class, sp->class, sf->flags & VSL_SF_CL_WC))
- continue;
- if (iter_test(sf->ident, sp->ident, sf->flags & VSL_SF_ID_WC))
- continue;
- if (iter_test(sf->name, sp->name, sf->flags & VSL_SF_NM_WC))
- continue;
- if (sf->flags & VSL_SF_EXCL)
- good = 0;
- else
- good = 1;
- }
- if (!good)
- return (0);
- return (func(priv, sp));
-}
-
-static int
-iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
- void *priv)
-{
- struct vsc_main *st = VSM_PTR(sha);
- struct vsl_statpt sp;
- int i;
-
- sp.class = "";
- sp.ident = "";
-#define VSC_F_MAIN(nn, tt, ll, ff, dd) \
- sp.name = #nn; \
- sp.fmt = #tt; \
- sp.flag = ff; \
- sp.desc = dd; \
- sp.ptr = &st->nn; \
- i = iter_call(vd, func, priv, &sp); \
- if (i) \
- return(i);
-#include "vsc_fields.h"
-#undef VSC_F_MAIN
- return (0);
-}
-
-static int
-iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
- void *priv)
-{
- struct vsc_sma *st = VSM_PTR(sha);
- struct vsl_statpt sp;
- int i;
-
- sp.class = VSC_TYPE_SMA;
- sp.ident = sha->ident;
-#define VSC_F_SMA(nn, tt, ll, ff, dd) \
- sp.name = #nn; \
- sp.fmt = #tt; \
- sp.flag = ff; \
- sp.desc = dd; \
- sp.ptr = &st->nn; \
- i = iter_call(vd, func, priv, &sp); \
- if (i) \
- return(i);
-#include "vsc_fields.h"
-#undef VSC_F_SMA
- return (0);
-}
-
-int
-VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv)
-{
- struct vsm_chunk *sha;
- int i;
-
- i = 0;
- VSM_FOREACH(sha, vd) {
- CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
- if (strcmp(sha->class, VSC_CLASS))
- continue;
- if (!strcmp(sha->type, VSC_TYPE_MAIN))
- i = iter_main(vd, sha, func, priv);
- else if (!strcmp(sha->type, VSC_TYPE_SMA))
- i = iter_sma(vd, sha, func, priv);
- else
- i = -1;
- if (i != 0)
- break;
- }
- return (i);
-}
More information about the varnish-commit
mailing list