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

« back to all changes in this revision

Viewing changes to bin/varnishd/cache_vary.c

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen, Stig Sandbeck Mathisen, Michael Stapelberg
  • Date: 2013-06-29 16:20:51 UTC
  • mfrom: (0.1.17)
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: package-import@ubuntu.com-20130629162051-pp27htm7de22k4ow
[ Stig Sandbeck Mathisen ]
* New upstream release
* Add dep8 tests.
  Thanks to Yolanda Robla <yolanda.robla@canonical.com> (Closes: #710001)
* Advertise "reload" in the init script help (Closes: #710525)

[ Michael Stapelberg ]
* use dh-systemd for proper systemd-related maintscripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
#include "vend.h"
62
62
#include "vct.h"
63
63
 
64
 
struct vsb *
65
 
VRY_Create(const struct sess *sp, const struct http *hp)
 
64
/**********************************************************************
 
65
 * Create a Vary matching string from a Vary header
 
66
 *
 
67
 * Return value:
 
68
 * <0: Parse error
 
69
 *  0: No Vary header on object
 
70
 * >0: Length of Vary matching string in *psb
 
71
 */
 
72
 
 
73
int
 
74
VRY_Create(const struct sess *sp, const struct http *hp, struct vsb **psb)
66
75
{
67
76
        char *v, *p, *q, *h, *e;
68
77
        struct vsb *sb, *sbh;
69
78
        int l;
 
79
        int error = 0;
 
80
 
 
81
        AN(psb);
 
82
        AZ(*psb);
70
83
 
71
84
        /* No Vary: header, no worries */
72
85
        if (!http_GetHdr(hp, H_Vary, &v))
73
 
                return (NULL);
 
86
                return (0);
74
87
 
75
88
        /* For vary matching string */
76
89
        sb = VSB_new_auto();
80
93
        sbh = VSB_new_auto();
81
94
        AN(sbh);
82
95
 
83
 
        if (*v == ':') {
84
 
                WSP(sp, SLT_Error, "Vary header had extra ':', fix backend");
85
 
                v++;
86
 
        }
87
96
        for (p = v; *p; p++) {
88
97
 
89
98
                /* Find next header-name */
92
101
                for (q = p; *q && !vct_issp(*q) && *q != ','; q++)
93
102
                        continue;
94
103
 
 
104
                if (q - p > INT8_MAX) {
 
105
                        WSP(sp, SLT_Error, "Vary header name length exceeded");
 
106
                        error = 1;
 
107
                        break;
 
108
                }
 
109
 
95
110
                /* Build a header-matching string out of it */
96
111
                VSB_clear(sbh);
97
112
                VSB_printf(sbh, "%c%.*s:%c",
106
121
                                e--;
107
122
                        /* Encode two byte length and contents */
108
123
                        l = e - h;
109
 
                        assert(!(l & ~0xffff));
 
124
                        if (l > 0xffff - 1) {
 
125
                                WSP(sp, SLT_Error,
 
126
                                    "Vary header maximum length exceeded");
 
127
                                error = 1;
 
128
                                break;
 
129
                        }
110
130
                } else {
111
131
                        e = h;
112
132
                        l = 0xffff;
121
141
                        q++;
122
142
                if (*q == '\0')
123
143
                        break;
124
 
                xxxassert(*q == ',');
 
144
                if (*q != ',') {
 
145
                        WSP(sp, SLT_Error, "Malformed Vary header");
 
146
                        error = 1;
 
147
                        break;
 
148
                }
125
149
                p = q;
126
150
        }
 
151
 
 
152
        if (error) {
 
153
                VSB_delete(sbh);
 
154
                VSB_delete(sb);
 
155
                return (-1);
 
156
        }
 
157
 
127
158
        /* Terminate vary matching string */
128
159
        VSB_printf(sb, "%c%c%c", 0xff, 0xff, 0);
129
160
 
130
161
        VSB_delete(sbh);
131
162
        AZ(VSB_finish(sb));
132
 
        return(sb);
 
163
        *psb = sb;
 
164
        return (VSB_len(sb));
133
165
}
134
166
 
135
167
/*