MCPcopy Create free account
hub / github.com/apache/httpd / ap_escape_logitem

Function ap_escape_logitem

server/util.c:2183–2249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2181 return x;
2182}
2183AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str)
2184{
2185 char *ret;
2186 unsigned char *d;
2187 const unsigned char *s;
2188 apr_size_t length, escapes = 0;
2189
2190 if (!str) {
2191 return NULL;
2192 }
2193
2194 /* Compute how many characters need to be escaped */
2195 s = (const unsigned char *)str;
2196 for (; *s; ++s) {
2197 if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) {
2198 escapes++;
2199 }
2200 }
2201
2202 /* Compute the length of the input string, including NULL */
2203 length = s - (const unsigned char *)str + 1;
2204
2205 /* Fast path: nothing to escape */
2206 if (escapes == 0) {
2207 return apr_pmemdup(p, str, length);
2208 }
2209
2210 /* Each escaped character needs up to 3 extra bytes (0 --> \x00) */
2211 ret = apr_palloc(p, length + 3 * escapes);
2212 d = (unsigned char *)ret;
2213 s = (const unsigned char *)str;
2214 for (; *s; ++s) {
2215 if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) {
2216 *d++ = '\\';
2217 switch(*s) {
2218 case '\b':
2219 *d++ = 'b';
2220 break;
2221 case '\n':
2222 *d++ = 'n';
2223 break;
2224 case '\r':
2225 *d++ = 'r';
2226 break;
2227 case '\t':
2228 *d++ = 't';
2229 break;
2230 case '\v':
2231 *d++ = 'v';
2232 break;
2233 case '\\':
2234 case '"':
2235 *d++ = *s;
2236 break;
2237 default:
2238 c2x(*s, 'x', d);
2239 d += 3;
2240 }

Callers 15

ap_process_async_requestFunction · 0.85
send_all_header_fieldsFunction · 0.85
ssl_var_log_handler_cFunction · 0.85
ssl_var_log_handler_xFunction · 0.85
cgi_child_errfnFunction · 0.85
status_handlerFunction · 0.85
h2_stream_end_headersFunction · 0.85
lua_ap_escape_logitemFunction · 0.85
log_remote_hostFunction · 0.85
log_remote_lognameFunction · 0.85
log_remote_userFunction · 0.85
log_request_lineFunction · 0.85

Calls 1

c2xFunction · 0.70

Tested by

no test coverage detected