]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mime_header.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mime_header.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 25 MiME Header Parsing */
10
11 #include "squid.h"
12 #include "Debug.h"
13 #include "profiler/Profiler.h"
14
15 size_t
16 headersEnd(const char *mime, size_t l)
17 {
18 size_t e = 0;
19 int state = 1;
20
21 PROF_start(headersEnd);
22
23 while (e < l && state < 3) {
24 switch (state) {
25
26 case 0:
27
28 if ('\n' == mime[e])
29 state = 1;
30
31 break;
32
33 case 1:
34 if ('\r' == mime[e])
35 state = 2;
36 else if ('\n' == mime[e])
37 state = 3;
38 else
39 state = 0;
40
41 break;
42
43 case 2:
44 if ('\n' == mime[e])
45 state = 3;
46 else
47 state = 0;
48
49 break;
50
51 default:
52 break;
53 }
54
55 ++e;
56 }
57 PROF_stop(headersEnd);
58
59 if (3 == state)
60 return e;
61
62 return 0;
63 }
64