~ubuntu-branches/ubuntu/trusty/varnish/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/libvarnish/vre.c

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen, Stig Sandbeck Mathisen, Tollef Fog Heen
  • Date: 2013-05-05 15:53:14 UTC
  • mfrom: (0.1.16)
  • Revision ID: package-import@ubuntu.com-20130505155314-i99wuol99cfwzrtv
Tags: 3.0.3-1
[ Stig Sandbeck Mathisen ]
* New upstream release

[ Tollef Fog Heen ]
* Make varnishlog's and varnishncsa's init script exit with the exit
  status of status_of_proc to make them useful.  Fixes upstream trac
  #1226.

[ Stig Sandbeck Mathisen ]
* Do not rewrite /etc/default/varnish on upgrade.
  Thanks to Andreas Beckmann <anbe@debian.org> (Closes: 698577)
* Undo mangling of /etc/default/varnish that happened during lenny->squeeze
  upgrade.
  Thanks to Andreas Beckmann <anbe@debian.org> (Closes: 698577)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 */
28
28
 
29
29
#include <pcre.h>
 
30
#include <string.h>
30
31
 
31
32
#include "libvarnish.h"
32
33
#include "miniobj.h"
35
36
struct vre {
36
37
        unsigned                magic;
37
38
#define VRE_MAGIC               0xe83097dc
38
 
        pcre *re;
 
39
        pcre                    *re;
 
40
        pcre_extra              *re_extra;
39
41
};
40
42
 
41
 
vre_t *VRE_compile(const char *pattern, int options,
42
 
                    const char **errptr, int *erroffset) {
 
43
#ifndef PCRE_STUDY_JIT_COMPILE
 
44
#define PCRE_STUDY_JIT_COMPILE 0
 
45
#endif
 
46
 
 
47
/*
 
48
 * We don't want to spread or even expose the majority of PCRE options
 
49
 * so we establish our own options and implement hard linkage to PCRE
 
50
 * here.
 
51
 */
 
52
const unsigned VRE_CASELESS = PCRE_CASELESS;
 
53
const unsigned VRE_NOTEMPTY = PCRE_NOTEMPTY;
 
54
 
 
55
vre_t *
 
56
VRE_compile(const char *pattern, int options,
 
57
                    const char **errptr, int *erroffset)
 
58
{
43
59
        vre_t *v;
44
60
        *errptr = NULL; *erroffset = 0;
45
61
 
46
62
        ALLOC_OBJ(v, VRE_MAGIC);
47
 
        AN(v);
 
63
        if (v == NULL)
 
64
                return (NULL);
48
65
        v->re = pcre_compile(pattern, options, errptr, erroffset, NULL);
49
66
        if (v->re == NULL) {
50
67
                VRE_free(&v);
51
 
                return NULL;
52
 
        }
53
 
        return v;
 
68
                return (NULL);
 
69
        }
 
70
        v->re_extra = pcre_study(v->re, PCRE_STUDY_JIT_COMPILE, errptr);
 
71
        if (v->re_extra == NULL) {
 
72
                if (*errptr != NULL) {
 
73
                        VRE_free(&v);
 
74
                        return (NULL);
 
75
                }
 
76
                /* allocate our own, pcre_study can return NULL without it
 
77
                 * being an error */
 
78
                v->re_extra = calloc(1, sizeof(pcre_extra));
 
79
                if (v->re_extra == NULL) {
 
80
                        VRE_free(&v);
 
81
                        return (NULL);
 
82
                }
 
83
        }
 
84
        return (v);
54
85
}
55
86
 
56
 
int VRE_exec(const vre_t *code, const char *subject, int length,
57
 
             int startoffset, int options, int *ovector, int ovecsize) {
 
87
int
 
88
VRE_exec(const vre_t *code, const char *subject, int length,
 
89
    int startoffset, int options, int *ovector, int ovecsize,
 
90
    const volatile struct vre_limits *lim)
 
91
{
58
92
        CHECK_OBJ_NOTNULL(code, VRE_MAGIC);
59
93
        int ov[30];
 
94
 
60
95
        if (ovector == NULL) {
61
96
                ovector = ov;
62
97
                ovecsize = sizeof(ov)/sizeof(ov[0]);
63
98
        }
64
99
 
65
 
        return pcre_exec(code->re, NULL, subject, length,
66
 
                         startoffset, options, ovector, ovecsize);
 
100
        if (lim != NULL) {
 
101
                code->re_extra->match_limit = lim->match;
 
102
                code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT;
 
103
                code->re_extra->match_limit_recursion = lim->match_recursion;
 
104
                code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
 
105
        } else {
 
106
                code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
 
107
                code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION;
 
108
        }
 
109
 
 
110
        return (pcre_exec(code->re, code->re_extra, subject, length,
 
111
            startoffset, options, ovector, ovecsize));
67
112
}
68
113
 
69
 
void VRE_free(vre_t **vv) {
70
 
 
 
114
void
 
115
VRE_free(vre_t **vv)
 
116
{
71
117
        vre_t *v = *vv;
72
118
 
73
119
        *vv = NULL;
74
120
        CHECK_OBJ(v, VRE_MAGIC);
 
121
#ifdef PCRE_CONFIG_JIT
 
122
        pcre_free_study(v->re_extra);
 
123
#else
 
124
        free(v->re_extra);
 
125
#endif
75
126
        pcre_free(v->re);
76
 
        v->magic = 0;
77
127
        FREE_OBJ(v);
78
128
}