RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / include / linux / netfilter_mime.h
blob7eeb18352f44ee0065e4d4a429f37da52ec6ed50
1 /*
2 * MIME functions for netfilter modules. This file provides implementations
3 * for basic MIME parsing. MIME headers are used in many protocols, such as
4 * HTTP, RTSP, SIP, etc.
6 * gcc will warn for defined but unused functions, so we only include the
7 * functions requested. The following macros are used:
8 * NF_NEED_MIME_NEXTLINE nf_mime_nextline()
9 */
10 #ifndef _NETFILTER_MIME_H
11 #define _NETFILTER_MIME_H
13 /* Only include these functions for kernel code. */
14 #ifdef __KERNEL__
16 #include <linux/ctype.h>
19 * Given a buffer and length, advance to the next line and mark the current
20 * line. If the current line is empty, *plinelen will be set to zero. If
21 * not, it will be set to the actual line length (including CRLF).
23 * 'line' in this context means logical line (includes LWS continuations).
24 * Returns 1 on success, 0 on failure.
26 #ifdef NF_NEED_MIME_NEXTLINE
27 static int
28 nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
30 uint off = *poff;
31 uint physlen = 0;
32 int is_first_line = 1;
34 if (off >= len)
36 return 0;
41 while (p[off] != '\n')
43 if (len-off <= 1)
45 return 0;
48 physlen++;
49 off++;
52 /* if we saw a crlf, physlen needs adjusted */
53 if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
55 physlen--;
58 /* advance past the newline */
59 off++;
61 /* check for an empty line */
62 if (physlen == 0)
64 break;
67 /* check for colon on the first physical line */
68 if (is_first_line)
70 is_first_line = 0;
71 if (memchr(p+(*poff), ':', physlen) == NULL)
73 return 0;
77 while (p[off] == ' ' || p[off] == '\t');
79 *plineoff = *poff;
80 *plinelen = (physlen == 0) ? 0 : (off - *poff);
81 *poff = off;
83 return 1;
85 #endif /* NF_NEED_MIME_NEXTLINE */
87 #endif /* __KERNEL__ */
89 #endif /* _NETFILTER_MIME_H */