varnish-cache/lib/libvmod_debug/vmod_debug_obj.c
1
/*-
2
 * Copyright (c) 2013-2015 Varnish Software AS
3
 * All rights reserved.
4
 *
5
 * Author: Poul-Henning Kamp <phk@FreeBSD.org>
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
 * SUCH DAMAGE.
27
 */
28
29
#include "config.h"
30
31
#include <stdlib.h>
32
#include <string.h>
33
34
#include "cache/cache.h"
35
36
#include "vcc_if.h"
37
38
struct xyzzy_debug_obj {
39
        unsigned                magic;
40
#define VMOD_DEBUG_OBJ_MAGIC    0xccbd9b77
41
        int foobar;
42
        const char *string, *number;
43
};
44
45
VCL_VOID
46 24
xyzzy_obj__init(VRT_CTX, struct xyzzy_debug_obj **op,
47
    const char *vcl_name, VCL_STRING s, VCL_ENUM e)
48
{
49
        struct xyzzy_debug_obj *o;
50
51 24
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
52
        (void)vcl_name;
53 24
        AN(op);
54 24
        AZ(*op);
55 24
        ALLOC_OBJ(o, VMOD_DEBUG_OBJ_MAGIC);
56 24
        AN(o);
57 24
        *op = o;
58 24
        o->foobar = 42;
59 24
        o->string = s;
60 24
        o->number = e;
61 24
        AN(*op);
62 24
}
63
64
VCL_VOID
65 2
xyzzy_obj__fini(struct xyzzy_debug_obj **op)
66
{
67
68 2
        AN(op);
69 2
        AN(*op);
70 2
        FREE_OBJ(*op);
71 2
        *op = NULL;
72 2
}
73
74
VCL_VOID v_matchproto_()
75 2
xyzzy_obj_enum(VRT_CTX, struct xyzzy_debug_obj *o, VCL_ENUM e)
76
{
77
78 2
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
79 2
        CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
80 2
        assert(!strcmp(e, "martin"));
81 2
}
82
83
VCL_STRING v_matchproto_()
84 2
xyzzy_obj_foo(VRT_CTX, struct xyzzy_debug_obj *o, VCL_STRING s)
85
{
86
87 2
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
88
        (void)s;
89 2
        CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
90 2
        assert(o->foobar == 42);
91 2
        return ("BOO");
92
}
93
94
VCL_TIME v_matchproto_()
95 0
xyzzy_obj_date(VRT_CTX, struct xyzzy_debug_obj *o)
96
{
97
98 0
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
99 0
        CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
100 0
        assert(o->foobar == 42);
101 0
        return (21.4);
102
}
103
104
VCL_STRING v_matchproto_()
105 12
xyzzy_obj_string(VRT_CTX, struct xyzzy_debug_obj *o)
106
{
107
108 12
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
109 12
        CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
110 12
        assert(o->foobar == 42);
111 12
        return (o->string);
112
}
113
114
VCL_STRING v_matchproto_()
115 12
xyzzy_obj_number(VRT_CTX, struct xyzzy_debug_obj *o)
116
{
117
118 12
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
119 12
        CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
120 12
        assert(o->foobar == 42);
121 12
        return (o->number);
122
}
123
124
VCL_VOID v_matchproto_()
125 2
xyzzy_obj_test_priv_call(VRT_CTX,
126
    struct xyzzy_debug_obj *o, struct vmod_priv *priv)
127
{
128
        (void)o;
129 2
        xyzzy_test_priv_call(ctx, priv);
130 2
}
131
VCL_VOID v_matchproto_()
132 2
xyzzy_obj_test_priv_vcl(VRT_CTX,
133
    struct xyzzy_debug_obj *o, struct vmod_priv *priv)
134
{
135
        (void)o;
136 2
        xyzzy_test_priv_vcl(ctx, priv);
137 2
}
138
VCL_STRING v_matchproto_()
139 26
xyzzy_obj_test_priv_task(VRT_CTX,
140
    struct xyzzy_debug_obj *o, struct vmod_priv *priv, VCL_STRING s)
141
{
142
        (void)o;
143 26
        return (xyzzy_test_priv_task(ctx, priv, s));
144
}
145
VCL_STRING v_matchproto_()
146 8
xyzzy_obj_test_priv_top(VRT_CTX,
147
    struct xyzzy_debug_obj *o, struct vmod_priv *priv, VCL_STRING s)
148
{
149
        (void)o;
150 8
        return (xyzzy_test_priv_top(ctx, priv, s));
151
}