~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/HttpHeaderTools.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2009-09-24 14:51:06 UTC
  • mfrom: (1.1.12 upstream)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090924145106-38jgrzmj0d73pha5
Tags: 3.1.0.13-1
* Upload to experimental

* New upstream release
  - Fixes Follow-X-Forwarded-For support (Closes: #523943)
  - Adds IPv6 support (Closes: #432351)

* debian/rules
  - Removed obsolete configuration options
  - Enable db and radius basic authentication modules

* debian/patches/01-cf.data.debian
  - Adapted to new upstream version

* debian/patches/02-makefile-defaults
  - Adapted to new upstream version

* debian/{squid.postinst,squid.rc,README.Debian,watch}
  - Updated references to squid 3.1

* debian/squid3.install
  - Install CSS file for error pages
  - Install manual pages for new authentication modules

* debian/squid3-common.install
  - Install documented version of configuration file in /usr/share/doc/squid3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
 
 * $Id: HttpHeaderTools.cc,v 1.63 2007/09/28 00:22:37 hno Exp $
 
3
 * $Id$
4
4
 *
5
5
 * DEBUG: section 66    HTTP Header Tools
6
6
 * AUTHOR: Alex Rousskov
21
21
 *  it under the terms of the GNU General Public License as published by
22
22
 *  the Free Software Foundation; either version 2 of the License, or
23
23
 *  (at your option) any later version.
24
 
 *  
 
24
 *
25
25
 *  This program is distributed in the hope that it will be useful,
26
26
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
27
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
28
 *  GNU General Public License for more details.
29
 
 *  
 
29
 *
30
30
 *  You should have received a copy of the GNU General Public License
31
31
 *  along with this program; if not, write to the Free Software
32
32
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36
36
#include "squid.h"
37
37
#include "HttpHeader.h"
38
38
#include "HttpHdrContRange.h"
39
 
#include "ACLChecklist.h"
 
39
#include "acl/FilledChecklist.h"
40
40
#include "MemBuf.h"
41
41
 
42
42
static void httpHeaderPutStrvf(HttpHeader * hdr, http_hdr_type id, const char *fmt, va_list vargs);
86
86
    memset(mask, value, sizeof(*mask));
87
87
}
88
88
 
89
 
/* calculates a bit mask of a given array; does not reset mask! */
 
89
/** calculates a bit mask of a given array; does not reset mask! */
90
90
void
91
91
httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count)
92
92
{
103
103
 
104
104
/* same as httpHeaderPutStr, but formats the string using snprintf first */
105
105
void
106
 
#if STDC_HEADERS
107
106
httpHeaderPutStrf(HttpHeader * hdr, http_hdr_type id, const char *fmt,...)
108
 
#else
109
 
httpHeaderPutStrf(va_alist)
110
 
va_dcl
111
 
#endif
112
107
{
113
 
#if STDC_HEADERS
114
108
    va_list args;
115
109
    va_start(args, fmt);
116
 
#else
117
 
 
118
 
    va_list args;
119
 
    HttpHeader *hdr = NULL;
120
 
    http_hdr_type id = HDR_ENUM_END;
121
 
    const char *fmt = NULL;
122
 
    va_start(args);
123
 
    hdr = va_arg(args, HttpHeader *);
124
 
    id = va_arg(args, http_hdr_type);
125
 
    fmt = va_arg(args, char *);
126
 
#endif
127
110
 
128
111
    httpHeaderPutStrvf(hdr, id, fmt, args);
129
112
    va_end(args);
141
124
}
142
125
 
143
126
 
144
 
/* wrapper arrounf PutContRange */
 
127
/** wrapper arrounf PutContRange */
145
128
void
146
129
httpHeaderAddContRange(HttpHeader * hdr, HttpHdrRangeSpec spec, int64_t ent_len)
147
130
{
153
136
}
154
137
 
155
138
 
156
 
/*
 
139
/**
157
140
 * return true if a given directive is found in at least one of
158
141
 * the "connection" header-fields note: if HDR_PROXY_CONNECTION is
159
142
 * present we ignore HDR_CONNECTION.
182
165
    return res;
183
166
}
184
167
 
185
 
/* returns true iff "m" is a member of the list */
 
168
/** returns true iff "m" is a member of the list */
186
169
int
187
170
strListIsMember(const String * list, const char *m, char del)
188
171
{
201
184
    return 0;
202
185
}
203
186
 
204
 
/* returns true iff "s" is a substring of a member of the list */
 
187
/** returns true iff "s" is a substring of a member of the list */
205
188
int
206
189
strListIsSubstr(const String * list, const char *s, char del)
207
190
{
208
191
    assert(list && del);
209
 
    return list->pos(s) != 0;
 
192
    return (list->find(s) != String::npos);
210
193
 
211
 
    /*
 
194
    /** \note
212
195
     * Note: the original code with a loop is broken because it uses strstr()
213
196
     * instead of strnstr(). If 's' contains a 'del', strListIsSubstr() may
214
197
     * return true when it should not. If 's' does not contain a 'del', the
217
200
     */
218
201
}
219
202
 
220
 
/* appends an item to the list */
 
203
/** appends an item to the list */
221
204
void
222
205
strListAdd(String * str, const char *item, char del)
223
206
{
234
217
    str->append(item, strlen(item));
235
218
}
236
219
 
237
 
/*
 
220
/**
238
221
 * iterates through a 0-terminated string of items separated by 'del's.
239
222
 * white space around 'del' is considered to be a part of 'del'
240
223
 * like strtok, but preserves the source, and can iterate several strings at once
246
229
strListGetItem(const String * str, char del, const char **item, int *ilen, const char **pos)
247
230
{
248
231
    size_t len;
249
 
 
250
 
    /* ',' is always enabled as field delimiter as this is required for
251
 
     * processing merged header values properly, even if Cookie normally
252
 
     * uses ';' as delimiter.
253
 
     */
254
 
    static char delim[3][8] =
255
 
    {
256
 
        "\"?,",
257
 
        "\"\\",
258
 
        " ?,\t\r\n"
 
232
    static char delim[3][8] = {
 
233
        "\"?,",
 
234
        "\"\\",
 
235
        " ?,\t\r\n"
259
236
    };
260
237
    int quoted = 0;
261
238
    assert(str && item && pos);
264
241
    delim[2][1] = del;
265
242
 
266
243
    if (!*pos) {
267
 
        *pos = str->buf();
 
244
        *pos = str->termedBuf();
268
245
 
269
246
        if (!*pos)
270
247
            return 0;
271
248
    }
272
249
 
273
 
    /* skip leading whitespace and delimiters */
 
250
    /* skip leading ws and delimiters */
274
251
    *pos += strspn(*pos, delim[2]);
275
252
 
276
253
    *item = *pos;               /* remember item's start */
278
255
    /* find next delimiter */
279
256
    do {
280
257
        *pos += strcspn(*pos, delim[quoted]);
 
258
 
 
259
        if (**pos == del)
 
260
            break;
 
261
 
281
262
        if (**pos == '"') {
282
263
            quoted = !quoted;
283
264
            *pos += 1;
284
 
        } else if (quoted && **pos == '\\') {
 
265
        }
 
266
 
 
267
        if (quoted && **pos == '\\') {
285
268
            *pos += 1;
 
269
 
286
270
            if (**pos)
287
271
                *pos += 1;
288
 
        } else {
289
 
            break;              /* Delimiter found, marking the end of this value */
290
272
        }
291
273
    } while (**pos);
292
274
 
302
284
    return len > 0;
303
285
}
304
286
 
305
 
/* handy to printf prefixes of potentially very long buffers */
 
287
/** handy to printf prefixes of potentially very long buffers */
306
288
const char *
307
289
getStringPrefix(const char *str, const char *end)
308
290
{
313
295
    return buf;
314
296
}
315
297
 
316
 
/*
 
298
/**
317
299
 * parses an int field, complains if soemthing went wrong, returns true on
318
300
 * success
319
301
 */
337
319
    errno = 0;
338
320
    int64_t res = strtoll(start, NULL, 10);
339
321
    if (!res && EINVAL == errno)        /* maybe not portable? */
340
 
        return 0;
 
322
        return 0;
341
323
    *value = res;
342
324
    return 1;
343
325
}
344
326
 
345
327
 
346
 
/* Parses a quoted-string field (RFC 2616 section 2.2), complains if
 
328
/**
 
329
 * Parses a quoted-string field (RFC 2616 section 2.2), complains if
347
330
 * something went wrong, returns non-zero on success.
348
331
 * start should point at the first ".
349
332
 * RC TODO: This is too looose. We should honour the BNF and exclude CTL's
374
357
    }
375
358
}
376
359
 
377
 
/*
378
 
 * httpHdrMangle checks the anonymizer (header_access) configuration.
379
 
 * Returns 1 if the header is allowed.
 
360
/**
 
361
 * Checks the anonymizer (header_access) configuration.
 
362
 *
 
363
 * \retval 0    Header is explicitly blocked for removal
 
364
 * \retval 1    Header is explicitly allowed
 
365
 * \retval 1    Header has been replaced, the current version can be used.
 
366
 * \retval 1    Header has no access controls to test
380
367
 */
381
368
static int
382
369
httpHdrMangle(HttpHeaderEntry * e, HttpRequest * request, int req_or_rep)
385
372
 
386
373
    /* check with anonymizer tables */
387
374
    header_mangler *hm;
388
 
    ACLChecklist *checklist;
389
375
    assert(e);
390
376
 
391
377
    if (ROR_REQUEST == req_or_rep) {
397
383
        hm = &Config.request_header_access[e->id];
398
384
    }
399
385
 
400
 
    checklist = aclChecklistCreate(hm->access_list, request, NULL);
401
 
 
402
 
    if (1 == checklist->fastCheck()) {
403
 
        /* aclCheckFast returns 1 for allow. */
 
386
    /* mangler or checklist went away. default allow */
 
387
    if (!hm || !hm->access_list) {
 
388
        return 1;
 
389
    }
 
390
 
 
391
    ACLFilledChecklist checklist(hm->access_list, request, NULL);
 
392
 
 
393
    if (checklist.fastCheck()) {
 
394
        /* aclCheckFast returns true for allow. */
404
395
        retval = 1;
405
396
    } else if (NULL == hm->replacement) {
406
397
        /* It was denied, and we don't have any replacement */
414
405
        retval = 1;
415
406
    }
416
407
 
417
 
    delete checklist;
418
408
    return retval;
419
409
}
420
410
 
421
 
/* Mangles headers for a list of headers. */
 
411
/** Mangles headers for a list of headers. */
422
412
void
423
413
httpHdrMangleList(HttpHeader * l, HttpRequest * request, int req_or_rep)
424
414
{
434
424
        l->refreshMask();
435
425
}
436
426
 
437
 
/*
 
427
/**
438
428
 * return 1 if manglers are configured.  Used to set a flag
439
429
 * for optimization during request forwarding.
440
430
 */