source: lib/libvmod_std/vmod_std_conversions.c @ 8aa1d8

Revision 8aa1d8, 2.6 KB checked in by Poul-Henning Kamp <phk@…>, 3 years ago (diff)

Eliminate nested <*.h> includes from include/*

Sort #includes according to rules which are for me to know and you
to guess.

  • Property mode set to 100644
Line 
1/*-
2 * Copyright (c) 2010-2011 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
30#include "config.h"
31
32#include <ctype.h>
33#include <errno.h>
34#include <math.h>
35#include <stdint.h>
36#include <stdlib.h>
37
38#include "../../bin/varnishd/cache.h"
39
40#include "vrt.h"
41#include "vcc_if.h"
42
43double __match_proto__()
44vmod_duration(struct sess *sp, const char *p, double d)
45{
46        char *e;
47        double r;
48
49        (void)sp;
50
51        if (p == NULL)
52                return (d);
53
54        while(isspace(*p))
55                p++;
56
57        if (*p != '+' && *p != '-' && !isdigit(*p))
58                return (d);
59
60        e = NULL;
61
62        r = strtod(p, &e);
63
64        if (!isfinite(r))
65                return (d);
66
67        if (e == NULL)
68                return (d);
69
70        while(isspace(*e))
71                e++;
72
73        /* NB: Keep this list synchronized with VCC */
74        switch (*e++) {
75        case 's': break;
76        case 'm': r *= 60.; break;
77        case 'h': r *= 60.*60.; break;
78        case 'd': r *= 60.*60.*24.; break;
79        case 'w': r *= 60.*60.*24.*7.; break;
80        default:
81                return (d);
82        }
83
84        while(isspace(*e))
85                e++;
86
87        if (*e != '\0')
88                return (d);
89
90        return (r);
91}
92
93int __match_proto__()
94vmod_integer(struct sess *sp, const char *p, int i)
95{
96        char *e;
97        int r;
98
99        (void)sp;
100
101        if (p == NULL)
102                return (i);
103
104        while(isspace(*p))
105                p++;
106
107        if (*p != '+' && *p != '-' && !isdigit(*p))
108                return (i);
109
110        e = NULL;
111
112        r = strtol(p, &e, 0);
113
114        if (e == NULL)
115                return (i);
116
117        if (*e != '\0')
118                return (i);
119
120        return (r);
121}
Note: See TracBrowser for help on using the repository browser.