Root/
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. |
5 | * |
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 |
12 | |
13 | /* Only include these functions for kernel code. */ |
14 | #ifdef __KERNEL__ |
15 | |
16 | #include <linux/ctype.h> |
17 | |
18 | /* |
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). |
22 | * |
23 | * 'line' in this context means logical line (includes LWS continuations). |
24 | * Returns 1 on success, 0 on failure. |
25 | */ |
26 | #ifdef NF_NEED_MIME_NEXTLINE |
27 | static int |
28 | nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen) |
29 | { |
30 | uint off = *poff; |
31 | uint physlen = 0; |
32 | int is_first_line = 1; |
33 | |
34 | if (off >= len) |
35 | { |
36 | return 0; |
37 | } |
38 | |
39 | do |
40 | { |
41 | while (p[off] != '\n') |
42 | { |
43 | if (len-off <= 1) |
44 | { |
45 | return 0; |
46 | } |
47 | |
48 | physlen++; |
49 | off++; |
50 | } |
51 | |
52 | /* if we saw a crlf, physlen needs adjusted */ |
53 | if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r') |
54 | { |
55 | physlen--; |
56 | } |
57 | |
58 | /* advance past the newline */ |
59 | off++; |
60 | |
61 | /* check for an empty line */ |
62 | if (physlen == 0) |
63 | { |
64 | break; |
65 | } |
66 | |
67 | /* check for colon on the first physical line */ |
68 | if (is_first_line) |
69 | { |
70 | is_first_line = 0; |
71 | if (memchr(p+(*poff), ':', physlen) == NULL) |
72 | { |
73 | return 0; |
74 | } |
75 | } |
76 | } |
77 | while (p[off] == ' ' || p[off] == '\t'); |
78 | |
79 | *plineoff = *poff; |
80 | *plinelen = (physlen == 0) ? 0 : (off - *poff); |
81 | *poff = off; |
82 | |
83 | return 1; |
84 | } |
85 | #endif /* NF_NEED_MIME_NEXTLINE */ |
86 | |
87 | #endif /* __KERNEL__ */ |
88 | |
89 | #endif /* _NETFILTER_MIME_H */ |
90 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9