]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mime_header.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 25 MiME Header Parsing */
13 #define GET_HDR_SZ 1024
15 #include "profiler/Profiler.h"
18 * returns a pointer to a field-value of the first matching field-name where
19 * field-value matches prefix if any
22 mime_get_header_field(const char *mime
, const char *name
, const char *prefix
)
24 LOCAL_ARRAY(char, header
, GET_HDR_SZ
);
28 const int namelen
= name
? strlen(name
) : 0;
29 const int preflen
= prefix
? strlen(prefix
) : 0;
37 debugs(25, 5, "mime_get_header: looking for '" << name
<< "'");
39 for (p
= mime
; *p
; p
+= strcspn(p
, "\n\r")) {
40 if (strcmp(p
, "\r\n\r\n") == 0 || strcmp(p
, "\n\n") == 0)
46 if (strncasecmp(p
, name
, namelen
))
49 if (!xisspace(p
[namelen
]) && p
[namelen
] != ':')
52 l
= strcspn(p
, "\n\r") + 1;
57 xstrncpy(header
, p
, l
);
59 debugs(25, 5, "mime_get_header: checking '" << header
<< "'");
70 while (xisspace(*q
)) {
76 /* we could process list entries here if we had strcasestr(). */
77 /* make sure we did not match a part of another field-value */
78 got
= !strncasecmp(q
, prefix
, preflen
) && !xisalpha(q
[preflen
]);
82 debugs(25, 5, "mime_get_header: returning '" << q
<< "'");
90 /* returns a pointer to a field-value of the first matching field-name */
92 mime_get_header(const char *mime
, const char *name
)
94 return mime_get_header_field(mime
, name
, NULL
);
98 headersEnd(const char *mime
, size_t l
)
103 PROF_start(headersEnd
);
105 while (e
< l
&& state
< 3) {
118 else if ('\n' == mime
[e
])
139 PROF_stop(headersEnd
);