]>
Commit | Line | Data |
---|---|---|
f7f3304a | 1 | #include "squid.h" |
38e16f92 | 2 | #include "format/Quoting.h" |
20efa1c2 AJ |
3 | |
4 | static const char c2x[] = | |
5 | "000102030405060708090a0b0c0d0e0f" | |
6 | "101112131415161718191a1b1c1d1e1f" | |
7 | "202122232425262728292a2b2c2d2e2f" | |
8 | "303132333435363738393a3b3c3d3e3f" | |
9 | "404142434445464748494a4b4c4d4e4f" | |
10 | "505152535455565758595a5b5c5d5e5f" | |
11 | "606162636465666768696a6b6c6d6e6f" | |
12 | "707172737475767778797a7b7c7d7e7f" | |
13 | "808182838485868788898a8b8c8d8e8f" | |
14 | "909192939495969798999a9b9c9d9e9f" | |
15 | "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf" | |
16 | "b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" | |
17 | "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" | |
18 | "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" | |
19 | "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" | |
20 | "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"; | |
21 | ||
22 | #if DEAD_USING_QUOTEMIMEBLOB | |
23 | /** copy of Log::QuoteMimeBlob. Bugs there will be found here. | |
24 | * This omits [] characters but is otherwise identical to Log::QuoteMimeBlob when OLD_LOG_MIME = 1 | |
25 | */ | |
26 | static char * | |
27 | username_quote(const char *header) | |
28 | { | |
29 | int c; | |
30 | int i; | |
31 | char *buf; | |
32 | char *buf_cursor; | |
33 | ||
34 | if (header == NULL) { | |
35 | buf = static_cast<char *>(xcalloc(1, 1)); | |
36 | *buf = '\0'; | |
37 | return buf; | |
38 | } | |
39 | ||
40 | buf = static_cast<char *>(xcalloc(1, (strlen(header) * 3) + 1)); | |
41 | buf_cursor = buf; | |
42 | /* | |
43 | * We escape: space \x00-\x1F and space (0x40) and \x7F-\xFF | |
44 | * to prevent garbage in the logs. CR and LF are also there just in case. | |
45 | */ | |
46 | ||
47 | while ((c = *(const unsigned char *) header++) != '\0') { | |
48 | if (c == '\r') { | |
aec55359 FC |
49 | *buf_cursor = '\\'; |
50 | ++buf_cursor; | |
51 | *buf_cursor = 'r'; | |
52 | ++buf_cursor; | |
20efa1c2 | 53 | } else if (c == '\n') { |
aec55359 FC |
54 | *buf_cursor = '\\'; |
55 | ++buf_cursor; | |
56 | *buf_cursor = 'n'; | |
57 | ++buf_cursor; | |
20efa1c2 AJ |
58 | } else if (c <= 0x1F |
59 | || c >= 0x7F | |
60 | || c == '%' | |
61 | || c == ' ') { | |
aec55359 FC |
62 | *buf_cursor = '%'; |
63 | ++buf_cursor; | |
20efa1c2 | 64 | i = c * 2; |
aec55359 FC |
65 | *buf_cursor = c2x[i]; |
66 | ++buf_cursor; | |
67 | *buf_cursor = c2x[i + 1]; | |
68 | ++buf_cursor; | |
20efa1c2 | 69 | } else { |
aec55359 FC |
70 | *buf_cursor = (char) c; |
71 | ++buf_cursor; | |
20efa1c2 AJ |
72 | } |
73 | } | |
74 | ||
75 | *buf_cursor = '\0'; | |
76 | return buf; | |
77 | } | |
78 | #endif // DEAD | |
79 | ||
80 | char * | |
38e16f92 | 81 | Format::QuoteUrlEncodeUsername(const char *name) |
20efa1c2 AJ |
82 | { |
83 | if (NULL == name) | |
84 | return NULL; | |
85 | ||
86 | if (name[0] == '\0') | |
87 | return NULL; | |
88 | ||
89 | return QuoteMimeBlob(name); | |
90 | // return username_quote(name); | |
91 | } | |
92 | ||
93 | char * | |
38e16f92 | 94 | Format::QuoteMimeBlob(const char *header) |
20efa1c2 AJ |
95 | { |
96 | int c; | |
97 | int i; | |
98 | char *buf; | |
99 | char *buf_cursor; | |
100 | ||
101 | if (header == NULL) { | |
102 | buf = static_cast<char *>(xcalloc(1, 1)); | |
103 | *buf = '\0'; | |
104 | return buf; | |
105 | } | |
106 | ||
107 | buf = static_cast<char *>(xcalloc(1, (strlen(header) * 3) + 1)); | |
108 | buf_cursor = buf; | |
109 | /** | |
110 | * Whe OLD_LOG_MIME is defined we escape: \x00-\x1F"#%;<>?{}|\\\\^~`\[\]\x7F-\xFF | |
111 | * which is the default escape list for the CPAN Perl5 URI module | |
112 | * modulo the inclusion of space (x40) to make the raw logs a bit | |
113 | * more readable. | |
114 | */ | |
115 | ||
116 | while ((c = *(const unsigned char *) header++) != '\0') { | |
117 | #if !OLD_LOG_MIME | |
118 | if (c == '\r') { | |
a38ec4b1 FC |
119 | *buf_cursor = '\\'; |
120 | ++buf_cursor; | |
121 | *buf_cursor = 'r'; | |
122 | ++buf_cursor; | |
20efa1c2 | 123 | } else if (c == '\n') { |
a38ec4b1 FC |
124 | *buf_cursor = '\\'; |
125 | ++buf_cursor; | |
126 | *buf_cursor = 'n'; | |
127 | ++buf_cursor; | |
20efa1c2 AJ |
128 | } else |
129 | #endif | |
130 | if (c <= 0x1F | |
131 | || c >= 0x7F | |
132 | || c == '%' | |
133 | #if OLD_LOG_MIME | |
134 | || c == '"' | |
135 | || c == '#' | |
136 | || c == ';' | |
137 | || c == '<' | |
138 | || c == '>' | |
139 | || c == '?' | |
140 | || c == '{' | |
141 | || c == '}' | |
142 | || c == '|' | |
143 | || c == '\\' | |
144 | || c == '^' | |
145 | || c == '~' | |
146 | || c == '`' | |
147 | #endif | |
148 | || c == '[' | |
149 | || c == ']') { | |
a38ec4b1 FC |
150 | *buf_cursor = '%'; |
151 | ++buf_cursor; | |
20efa1c2 | 152 | i = c * 2; |
a38ec4b1 FC |
153 | *buf_cursor = c2x[i]; |
154 | ++buf_cursor; | |
155 | *buf_cursor = c2x[i + 1]; | |
156 | ++buf_cursor; | |
20efa1c2 AJ |
157 | #if !OLD_LOG_MIME |
158 | ||
159 | } else if (c == '\\') { | |
a38ec4b1 FC |
160 | *buf_cursor = '\\'; |
161 | ++buf_cursor; | |
162 | *buf_cursor = '\\'; | |
163 | ++buf_cursor; | |
20efa1c2 AJ |
164 | #endif |
165 | ||
166 | } else { | |
a38ec4b1 FC |
167 | *buf_cursor = (char) c; |
168 | ++buf_cursor; | |
20efa1c2 AJ |
169 | } |
170 | } | |
171 | ||
172 | *buf_cursor = '\0'; | |
173 | return buf; | |
174 | } |