]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mime_header.cc
Drop useless function mime_get_header()
[thirdparty/squid.git] / src / mime_header.cc
1 /*
2 * DEBUG: section 25 MiME Header Parsing
3 * AUTHOR: Harvest Derived
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
33 #include "squid.h"
34
35 #define GET_HDR_SZ 1024
36 #include "Debug.h"
37 #include "profiler/Profiler.h"
38
39 /*
40 * returns a pointer to a field-value of the first matching field-name where
41 * field-value matches prefix if any
42 */
43 char *
44 mime_get_header_field(const char *mime, const char *name)
45 {
46 LOCAL_ARRAY(char, header, GET_HDR_SZ);
47 const char *p = NULL;
48 char *q = NULL;
49 char got = 0;
50 const int namelen = name ? strlen(name) : 0;
51 int l;
52
53 if (NULL == mime)
54 return NULL;
55
56 assert(NULL != name);
57
58 debugs(25, 5, "mime_get_header: looking for '" << name << "'");
59
60 for (p = mime; *p; p += strcspn(p, "\n\r")) {
61 if (strcmp(p, "\r\n\r\n") == 0 || strcmp(p, "\n\n") == 0)
62 return NULL;
63
64 while (xisspace(*p))
65 ++p;
66
67 if (strncasecmp(p, name, namelen))
68 continue;
69
70 if (!xisspace(p[namelen]) && p[namelen] != ':')
71 continue;
72
73 l = strcspn(p, "\n\r") + 1;
74
75 if (l > GET_HDR_SZ)
76 l = GET_HDR_SZ;
77
78 xstrncpy(header, p, l);
79
80 debugs(25, 5, "mime_get_header: checking '" << header << "'");
81
82 q = header;
83
84 q += namelen;
85
86 if (*q == ':') {
87 ++q;
88 got = 1;
89 }
90
91 while (xisspace(*q)) {
92 ++q;
93 got = 1;
94 }
95
96 if (got) {
97 debugs(25, 5, "mime_get_header: returning '" << q << "'");
98 return q;
99 }
100 }
101
102 return NULL;
103 }
104
105 size_t
106 headersEnd(const char *mime, size_t l)
107 {
108 size_t e = 0;
109 int state = 1;
110
111 PROF_start(headersEnd);
112
113 while (e < l && state < 3) {
114 switch (state) {
115
116 case 0:
117
118 if ('\n' == mime[e])
119 state = 1;
120
121 break;
122
123 case 1:
124 if ('\r' == mime[e])
125 state = 2;
126 else if ('\n' == mime[e])
127 state = 3;
128 else
129 state = 0;
130
131 break;
132
133 case 2:
134 if ('\n' == mime[e])
135 state = 3;
136 else
137 state = 0;
138
139 break;
140
141 default:
142 break;
143 }
144
145 ++e;
146 }
147 PROF_stop(headersEnd);
148
149 if (3 == state)
150 return e;
151
152 return 0;
153 }