Project

General

Profile

Feature #2236 ยป mod_accesslog.patch

crypt, 2010-07-12 02:55

View differences:

mod_accesslog.c 2010-05-23 04:56:02.000000000 +0200
162 162
	if (str->used == 0) return;
163 163
	buffer_prepare_append(dest, str->used - 1);
164 164

  
165
	for (unsigned int i = 0; i < str->used - 1; i++) {
166
		if (str->ptr[i] >= ' ' && str->ptr[i] <= '~') {
167
			/* printable chars */
168
			buffer_append_string_len(dest, &str->ptr[i], 1);
169
		} else switch (str->ptr[i]) {
170
		case '"':
171
			BUFFER_APPEND_STRING_CONST(dest, "\\\"");
172
			break;
173
		case '\\':
174
			BUFFER_APPEND_STRING_CONST(dest, "\\\\");
175
			break;
176
		case '\b':
177
			BUFFER_APPEND_STRING_CONST(dest, "\\b");
178
			break;
179
		case '\n':
180
			BUFFER_APPEND_STRING_CONST(dest, "\\n");
181
			break;
182
		case '\r':
183
			BUFFER_APPEND_STRING_CONST(dest, "\\r");
184
			break;
185
		case '\t':
186
			BUFFER_APPEND_STRING_CONST(dest, "\\t");
187
			break;
188
		case '\v':
189
			BUFFER_APPEND_STRING_CONST(dest, "\\v");
190
			break;
191
		default: {
192
				/* non printable char => \xHH */
193
				char hh[5] = {'\\','x',0,0,0};
194
				char h = str->ptr[i] / 16;
195
				hh[2] = (h > 9) ? (h - 10 + 'A') : (h + '0');
196
				h = str->ptr[i] % 16;
197
				hh[3] = (h > 9) ? (h - 10 + 'A') : (h + '0');
198
				buffer_append_string_len(dest, &hh[0], 4);
165
	char *ptr, *start, *end;
166

  
167
	for (ptr = start = str->ptr, end = str->ptr + str->used - 1; ptr < end; ptr++) {
168
		if (*ptr >= ' ' && *ptr <= '~') {
169
			/* void */
170
		} else {
171

  
172
			buffer_append_string_len(dest, start, ptr - start);
173
			start = ptr + 1;
174

  
175
			switch (*ptr) {
176
			case '"':
177
				BUFFER_APPEND_STRING_CONST(dest, "\\\"");
178
				break;
179
			case '\\':
180
				BUFFER_APPEND_STRING_CONST(dest, "\\\\");
181
				break;
182
			case '\b':
183
				BUFFER_APPEND_STRING_CONST(dest, "\\b");
184
				break;
185
			case '\n':
186
				BUFFER_APPEND_STRING_CONST(dest, "\\n");
187
				break;
188
			case '\r':
189
				BUFFER_APPEND_STRING_CONST(dest, "\\r");
190
				break;
191
			case '\t':
192
				BUFFER_APPEND_STRING_CONST(dest, "\\t");
193
				break;
194
			case '\v':
195
				BUFFER_APPEND_STRING_CONST(dest, "\\v");
196
				break;
197
			default: {
198
					/* non printable char => \xHH */
199
					char hh[5] = {'\\','x',0,0,0};
200
					char h = *ptr / 16;
201
					hh[2] = (h > 9) ? (h - 10 + 'A') : (h + '0');
202
					h = *ptr % 16;
203
					hh[3] = (h > 9) ? (h - 10 + 'A') : (h + '0');
204
					buffer_append_string_len(dest, &hh[0], 4);
205
				}
206
				break;
199 207
			}
200
			break;
201 208
		}
202 209
	}
210

  
211
	if (start < end) {
212
		buffer_append_string_len(dest, start, end - start);
213
	}
203 214
}
204 215

  
205 216
static int accesslog_parse_format(server *srv, format_fields *fields, buffer *format) {
    (1-1/1)