]> granicus.if.org Git - apache/blob - server/util_script.c
tweak ap_get_remote_host() so that the caller can find out if she got
[apache] / server / util_script.c
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  *    if any, must include the following acknowledgment:
21  *       "This product includes software developed by the
22  *        Apache Software Foundation (http://www.apache.org/)."
23  *    Alternately, this acknowledgment may appear in the software itself,
24  *    if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" must
27  *    not be used to endorse or promote products derived from this
28  *    software without prior written permission. For written
29  *    permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  *    nor may "Apache" appear in their name, without prior written
33  *    permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation.  For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  * Portions of this software are based upon public domain software
55  * originally written at the National Center for Supercomputing Applications,
56  * University of Illinois, Urbana-Champaign.
57  */
58
59 #include "apr.h"
60 #include "apr_lib.h"
61 #include "apr_strings.h"
62
63 #define APR_WANT_STRFUNC
64 #include "apr_want.h"
65
66 #if APR_HAVE_STDLIB_H
67 #include <stdlib.h>
68 #endif
69
70 #define CORE_PRIVATE
71 #include "ap_config.h"
72 #include "httpd.h"
73 #include "http_config.h"
74 #include "http_main.h"
75 #include "http_log.h"
76 #include "http_core.h"
77 #include "http_protocol.h"
78 #include "http_request.h"       /* for sub_req_lookup_uri() */
79 #include "util_script.h"
80 #include "util_date.h"          /* For parseHTTPdate() */
81 #include "util_ebcdic.h"
82
83 #ifdef OS2
84 #define INCL_DOS
85 #include <os2.h>
86 #endif
87
88 /*
89  * Various utility functions which are common to a whole lot of
90  * script-type extensions mechanisms, and might as well be gathered
91  * in one place (if only to avoid creating inter-module dependancies
92  * where there don't have to be).
93  */
94
95 #define MALFORMED_MESSAGE "malformed header from script. Bad header="
96 #define MALFORMED_HEADER_LENGTH_TO_SHOW 30
97
98 static char *http2env(apr_pool_t *a, char *w)
99 {
100     char *res = apr_pstrcat(a, "HTTP_", w, NULL);
101     char *cp = res;
102
103     while (*++cp) {
104         if (!apr_isalnum(*cp) && *cp != '_') {
105             *cp = '_';
106         }
107         else {
108             *cp = apr_toupper(*cp);
109         }
110     }
111
112     return res;
113 }
114
115 AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t)
116 {
117     apr_array_header_t *env_arr = apr_table_elts(t);
118     apr_table_entry_t *elts = (apr_table_entry_t *) env_arr->elts;
119     char **env = (char **) apr_palloc(p, (env_arr->nelts + 2) * sizeof(char *));
120     int i, j;
121     char *tz;
122     char *whack;
123
124     j = 0;
125     if (!apr_table_get(t, "TZ")) {
126         tz = getenv("TZ");
127         if (tz != NULL) {
128             env[j++] = apr_pstrcat(p, "TZ=", tz, NULL);
129         }
130     }
131     for (i = 0; i < env_arr->nelts; ++i) {
132         if (!elts[i].key) {
133             continue;
134         }
135         env[j] = apr_pstrcat(p, elts[i].key, "=", elts[i].val, NULL);
136         whack = env[j];
137         if (apr_isdigit(*whack)) {
138             *whack++ = '_';
139         }
140         while (*whack != '=') {
141             if (!apr_isalnum(*whack) && *whack != '_') {
142                 *whack = '_';
143             }
144             ++whack;
145         }
146         ++j;
147     }
148
149     env[j] = NULL;
150     return env;
151 }
152
153 AP_DECLARE(void) ap_add_common_vars(request_rec *r)
154 {
155     apr_table_t *e;
156     server_rec *s = r->server;
157     conn_rec *c = r->connection;
158     const char *rem_logname;
159     char *env_path;
160 #if defined(WIN32) || defined(OS2)
161     char *env_temp;
162 #endif
163     const char *host;
164     apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in);
165     apr_table_entry_t *hdrs = (apr_table_entry_t *) hdrs_arr->elts;
166     int i;
167     apr_port_t rport;
168     apr_sockaddr_t *remotesa;
169
170     /* use a temporary apr_table_t which we'll overlap onto
171      * r->subprocess_env later
172      */
173     e = apr_table_make(r->pool, 25 + hdrs_arr->nelts);
174
175     /* First, add environment vars from headers... this is as per
176      * CGI specs, though other sorts of scripting interfaces see
177      * the same vars...
178      */
179
180     for (i = 0; i < hdrs_arr->nelts; ++i) {
181         if (!hdrs[i].key) {
182             continue;
183         }
184
185         /* A few headers are special cased --- Authorization to prevent
186          * rogue scripts from capturing passwords; content-type and -length
187          * for no particular reason.
188          */
189
190         if (!strcasecmp(hdrs[i].key, "Content-type")) {
191             apr_table_addn(e, "CONTENT_TYPE", hdrs[i].val);
192         }
193         else if (!strcasecmp(hdrs[i].key, "Content-length")) {
194             apr_table_addn(e, "CONTENT_LENGTH", hdrs[i].val);
195         }
196         /*
197          * You really don't want to disable this check, since it leaves you
198          * wide open to CGIs stealing passwords and people viewing them
199          * in the environment with "ps -e".  But, if you must...
200          */
201 #ifndef SECURITY_HOLE_PASS_AUTHORIZATION
202         else if (!strcasecmp(hdrs[i].key, "Authorization") 
203                  || !strcasecmp(hdrs[i].key, "Proxy-Authorization")) {
204             continue;
205         }
206 #endif
207         else {
208             apr_table_addn(e, http2env(r->pool, hdrs[i].key), hdrs[i].val);
209         }
210     }
211
212     if (!(env_path = getenv("PATH"))) {
213         env_path = DEFAULT_PATH;
214     }
215     apr_table_addn(e, "PATH", apr_pstrdup(r->pool, env_path));
216
217 #ifdef WIN32
218     if (env_temp = getenv("SystemRoot")) {
219         apr_table_addn(e, "SystemRoot", env_temp);         
220     }
221     if (env_temp = getenv("COMSPEC")) {
222         apr_table_addn(e, "COMSPEC", env_temp);            
223     }
224     if (env_temp = getenv("WINDIR")) {
225         apr_table_addn(e, "WINDIR", env_temp);
226     }
227 #endif
228
229 #ifdef OS2
230     if ((env_temp = getenv("COMSPEC")) != NULL) {
231         apr_table_addn(e, "COMSPEC", env_temp);            
232     }
233     if ((env_temp = getenv("ETC")) != NULL) {
234         apr_table_addn(e, "ETC", env_temp);            
235     }
236     if ((env_temp = getenv("DPATH")) != NULL) {
237         apr_table_addn(e, "DPATH", env_temp);            
238     }
239     if ((env_temp = getenv("PERLLIB_PREFIX")) != NULL) {
240         apr_table_addn(e, "PERLLIB_PREFIX", env_temp);            
241     }
242 #endif
243
244     apr_table_addn(e, "SERVER_SIGNATURE", ap_psignature("", r));
245     apr_table_addn(e, "SERVER_SOFTWARE", ap_get_server_version());
246     apr_table_addn(e, "SERVER_NAME", ap_get_server_name(r));
247     apr_table_addn(e, "SERVER_ADDR", r->connection->local_ip);  /* Apache */
248     apr_table_addn(e, "SERVER_PORT",
249                   apr_psprintf(r->pool, "%u", ap_get_server_port(r)));
250     host = ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST, NULL);
251     if (host) {
252         apr_table_addn(e, "REMOTE_HOST", host);
253     }
254     apr_table_addn(e, "REMOTE_ADDR", c->remote_ip);
255     apr_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r));    /* Apache */
256     apr_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
257     apr_table_addn(e, "SCRIPT_FILENAME", r->filename);  /* Apache */
258
259     apr_socket_addr_get(&remotesa, APR_REMOTE, c->client_socket);
260     apr_sockaddr_port_get(&rport, remotesa);
261     apr_table_addn(e, "REMOTE_PORT", apr_psprintf(r->pool, "%d", rport));
262
263     if (r->user) {
264         apr_table_addn(e, "REMOTE_USER", r->user);
265     }
266     if (r->ap_auth_type) {
267         apr_table_addn(e, "AUTH_TYPE", r->ap_auth_type);
268     }
269     rem_logname = ap_get_remote_logname(r);
270     if (rem_logname) {
271         apr_table_addn(e, "REMOTE_IDENT", apr_pstrdup(r->pool, rem_logname));
272     }
273
274     /* Apache custom error responses. If we have redirected set two new vars */
275
276     if (r->prev) {
277         if (r->prev->args) {
278             apr_table_addn(e, "REDIRECT_QUERY_STRING", r->prev->args);
279         }
280         if (r->prev->uri) {
281             apr_table_addn(e, "REDIRECT_URL", r->prev->uri);
282         }
283     }
284
285     apr_table_overlap(r->subprocess_env, e, APR_OVERLAP_TABLES_SET);
286 }
287
288 /* This "cute" little function comes about because the path info on
289  * filenames and URLs aren't always the same. So we take the two,
290  * and find as much of the two that match as possible.
291  */
292
293 AP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info)
294 {
295     int lu = strlen(uri);
296     int lp = strlen(path_info);
297
298     while (lu-- && lp-- && uri[lu] == path_info[lp]);
299
300     if (lu == -1) {
301         lu = 0;
302     }
303
304     while (uri[lu] != '\0' && uri[lu] != '/') {
305         lu++;
306     }
307     return lu;
308 }
309
310 AP_DECLARE(void) ap_add_cgi_vars(request_rec *r)
311 {
312     apr_table_t *e = r->subprocess_env;
313
314     apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1");
315     apr_table_setn(e, "SERVER_PROTOCOL", r->protocol);
316     apr_table_setn(e, "REQUEST_METHOD", r->method);
317     apr_table_setn(e, "QUERY_STRING", r->args ? r->args : "");
318     apr_table_setn(e, "REQUEST_URI", r->unparsed_uri);
319
320     /* Note that the code below special-cases scripts run from includes,
321      * because it "knows" that the sub_request has been hacked to have the
322      * args and path_info of the original request, and not any that may have
323      * come with the script URI in the include command.  Ugh.
324      */
325
326     if (!strcmp(r->protocol, "INCLUDED")) {
327         apr_table_setn(e, "SCRIPT_NAME", r->uri);
328         if (r->path_info && *r->path_info) {
329             apr_table_setn(e, "PATH_INFO", r->path_info);
330         }
331     }
332     else if (!r->path_info || !*r->path_info) {
333         apr_table_setn(e, "SCRIPT_NAME", r->uri);
334     }
335     else {
336         int path_info_start = ap_find_path_info(r->uri, r->path_info);
337
338         apr_table_setn(e, "SCRIPT_NAME",
339                       apr_pstrndup(r->pool, r->uri, path_info_start));
340
341         apr_table_setn(e, "PATH_INFO", r->path_info);
342     }
343
344     if (r->path_info && r->path_info[0]) {
345         /*
346          * To get PATH_TRANSLATED, treat PATH_INFO as a URI path.
347          * Need to re-escape it for this, since the entire URI was
348          * un-escaped before we determined where the PATH_INFO began.
349          */
350         request_rec *pa_req;
351
352         pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r,
353                                        NULL);
354
355         if (pa_req->filename) {
356 #ifdef WIN32
357             char buffer[HUGE_STRING_LEN];
358 #endif
359             char *pt = apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info,
360                                   NULL);
361 #ifdef WIN32
362             /* We need to make this a real Windows path name */
363             GetFullPathName(pt, HUGE_STRING_LEN, buffer, NULL);
364             apr_table_setn(e, "PATH_TRANSLATED", apr_pstrdup(r->pool, buffer));
365 #else
366             apr_table_setn(e, "PATH_TRANSLATED", pt);
367 #endif
368         }
369         ap_destroy_sub_req(pa_req);
370     }
371 }
372
373
374 static int set_cookie_doo_doo(void *v, const char *key, const char *val)
375 {
376     apr_table_addn(v, key, val);
377     return 1;
378 }
379
380 AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
381                                        int (*getsfunc) (char *, int, void *),
382                                        void *getsfunc_data)
383 {
384     char x[MAX_STRING_LEN];
385     char *w, *l;
386     int p;
387     int cgi_status = HTTP_OK;
388     apr_table_t *merge;
389     apr_table_t *cookie_table;
390
391     if (buffer) {
392         *buffer = '\0';
393     }
394     w = buffer ? buffer : x;
395
396     /* temporary place to hold headers to merge in later */
397     merge = apr_table_make(r->pool, 10);
398
399     /* The HTTP specification says that it is legal to merge duplicate
400      * headers into one.  Some browsers that support Cookies don't like
401      * merged headers and prefer that each Set-Cookie header is sent
402      * separately.  Lets humour those browsers by not merging.
403      * Oh what a pain it is.
404      */
405     cookie_table = apr_table_make(r->pool, 2);
406     apr_table_do(set_cookie_doo_doo, cookie_table, r->err_headers_out, "Set-Cookie", NULL);
407
408     while (1) {
409
410         if ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data) == 0) {
411             ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
412                           "Premature end of script headers: %s", r->filename);
413             return HTTP_INTERNAL_SERVER_ERROR;
414         }
415
416         /* Delete terminal (CR?)LF */
417
418         p = strlen(w);
419              /* Indeed, the host's '\n':
420                 '\012' for UNIX; '\015' for MacOS; '\025' for OS/390
421                  -- whatever the script generates.
422              */                                  
423         if (p > 0 && w[p - 1] == '\n') {
424             if (p > 1 && w[p - 2] == CR) {
425                 w[p - 2] = '\0';
426             }
427             else {
428                 w[p - 1] = '\0';
429             }
430         }
431
432         /*
433          * If we've finished reading the headers, check to make sure any
434          * HTTP/1.1 conditions are met.  If so, we're done; normal processing
435          * will handle the script's output.  If not, just return the error.
436          * The appropriate thing to do would be to send the script process a
437          * SIGPIPE to let it know we're ignoring it, close the channel to the
438          * script process, and *then* return the failed-to-meet-condition
439          * error.  Otherwise we'd be waiting for the script to finish
440          * blithering before telling the client the output was no good.
441          * However, we don't have the information to do that, so we have to
442          * leave it to an upper layer.
443          */
444         if (w[0] == '\0') {
445             int cond_status = OK;
446
447             if ((cgi_status == HTTP_OK) && (r->method_number == M_GET)) {
448                 cond_status = ap_meets_conditions(r);
449             }
450             apr_table_overlap(r->err_headers_out, merge,
451                 APR_OVERLAP_TABLES_MERGE);
452             if (!apr_is_empty_table(cookie_table)) {
453                 /* the cookies have already been copied to the cookie_table */
454                 apr_table_unset(r->err_headers_out, "Set-Cookie");
455                 r->err_headers_out = apr_table_overlay(r->pool,
456                     r->err_headers_out, cookie_table);
457             }
458             return cond_status;
459         }
460
461         /* if we see a bogus header don't ignore it. Shout and scream */
462
463 #if APR_CHARSET_EBCDIC
464             /* Chances are that we received an ASCII header text instead of
465              * the expected EBCDIC header lines. Try to auto-detect:
466              */
467         if (!(l = strchr(w, ':'))) {
468             int maybeASCII = 0, maybeEBCDIC = 0;
469             unsigned char *cp, native;
470             apr_size_t inbytes_left, outbytes_left;
471
472             for (cp = w; *cp != '\0'; ++cp) {
473                 native = apr_xlate_conv_byte(ap_hdrs_from_ascii, *cp);
474                 if (isprint(*cp) && !isprint(native))
475                     ++maybeEBCDIC;
476                 if (!isprint(*cp) && isprint(native))
477                     ++maybeASCII;
478             }
479             if (maybeASCII > maybeEBCDIC) {
480                 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r->server,
481                              "CGI Interface Error: Script headers apparently ASCII: (CGI = %s)",
482                              r->filename);
483                 inbytes_left = outbytes_left = cp - w;
484                 apr_xlate_conv_buffer(ap_hdrs_from_ascii,
485                                       w, &inbytes_left, w, &outbytes_left);
486             }
487         }
488 #endif /*APR_CHARSET_EBCDIC*/
489         if (!(l = strchr(w, ':'))) {
490             char malformed[(sizeof MALFORMED_MESSAGE) + 1
491                            + MALFORMED_HEADER_LENGTH_TO_SHOW];
492
493             strcpy(malformed, MALFORMED_MESSAGE);
494             strncat(malformed, w, MALFORMED_HEADER_LENGTH_TO_SHOW);
495
496             if (!buffer) {
497                 /* Soak up all the script output - may save an outright kill */
498                 while ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data)) {
499                     continue;
500                 }
501             }
502
503             ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
504                           "%s: %s", malformed, r->filename);
505             return HTTP_INTERNAL_SERVER_ERROR;
506         }
507
508         *l++ = '\0';
509         while (*l && apr_isspace(*l)) {
510             ++l;
511         }
512
513         if (!strcasecmp(w, "Content-type")) {
514             char *tmp;
515
516             /* Nuke trailing whitespace */
517
518             char *endp = l + strlen(l) - 1;
519             while (endp > l && apr_isspace(*endp)) {
520                 *endp-- = '\0';
521             }
522
523             tmp = apr_pstrdup(r->pool, l);
524             ap_content_type_tolower(tmp);
525             r->content_type = tmp;
526         }
527         /*
528          * If the script returned a specific status, that's what
529          * we'll use - otherwise we assume 200 OK.
530          */
531         else if (!strcasecmp(w, "Status")) {
532             r->status = cgi_status = atoi(l);
533             r->status_line = apr_pstrdup(r->pool, l);
534         }
535         else if (!strcasecmp(w, "Location")) {
536             apr_table_set(r->headers_out, w, l);
537         }
538         else if (!strcasecmp(w, "Content-Length")) {
539             apr_table_set(r->headers_out, w, l);
540         }
541         else if (!strcasecmp(w, "Transfer-Encoding")) {
542             apr_table_set(r->headers_out, w, l);
543         }
544         /*
545          * If the script gave us a Last-Modified header, we can't just
546          * pass it on blindly because of restrictions on future values.
547          */
548         else if (!strcasecmp(w, "Last-Modified")) {
549             ap_update_mtime(r, ap_parseHTTPdate(l));
550             ap_set_last_modified(r);
551         }
552         else if (!strcasecmp(w, "Set-Cookie")) {
553             apr_table_add(cookie_table, w, l);
554         }
555         else {
556             apr_table_add(merge, w, l);
557         }
558     }
559 }
560
561 static int getsfunc_FILE(char *buf, int len, void *f)
562 {
563     return apr_file_gets(buf, len, (apr_file_t *) f) == APR_SUCCESS;
564 }
565
566 AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f,
567                                           char *buffer)
568 {
569     return ap_scan_script_header_err_core(r, buffer, getsfunc_FILE, f);
570 }
571
572 struct vastrs {
573     va_list args;
574     int arg;
575     const char *curpos;
576 };
577
578 static int getsfunc_STRING(char *w, int len, void *pvastrs)
579 {
580     struct vastrs *strs = (struct vastrs*) pvastrs;
581     const char *p;
582     int t;
583     
584     if (!strs->curpos || !*strs->curpos) 
585         return 0;
586     p = ap_strchr_c(strs->curpos, '\n');
587     if (p)
588         ++p;
589     else
590         p = ap_strchr_c(strs->curpos, '\0');
591     t = p - strs->curpos;
592     if (t > len)
593         t = len;
594     strncpy (w, strs->curpos, t);
595     w[t] = '\0';
596     if (!strs->curpos[t]) {
597         ++strs->arg;
598         strs->curpos = va_arg(strs->args, const char *);
599     }
600     else
601         strs->curpos += t;
602     return t;    
603 }
604
605 /* ap_scan_script_header_err_strs() accepts additional const char* args...
606  * each is treated as one or more header lines, and the first non-header
607  * character is returned to **arg, **data.  (The first optional arg is
608  * counted as 0.)
609  */
610 AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r, 
611                                                       char *buffer, 
612                                                       const char **termch,
613                                                       int *termarg, ...)
614 {
615     struct vastrs strs;
616     int res;
617
618     va_start(strs.args, termarg);
619     strs.arg = 0;
620     strs.curpos = va_arg(strs.args, char*);
621     res = ap_scan_script_header_err_core(r, buffer, getsfunc_STRING, (void *) &strs);
622     if (termch)
623         *termch = strs.curpos;
624     if (termarg)
625         *termarg = strs.arg;
626     va_end(strs.args);
627     return res;
628 }
629
630 AP_DECLARE(void) ap_send_size(apr_ssize_t size, request_rec *r)
631 {
632     /* XXX: this -1 thing is a gross hack */
633     if (size == (apr_ssize_t)-1) {
634         ap_rputs("    -", r);
635     }
636     else if (!size) {
637         ap_rputs("   0k", r);
638     }
639     else if (size < 1024) {
640         ap_rputs("   1k", r);
641     }
642     else if (size < 1048576) {
643         ap_rprintf(r, "%4" APR_SSIZE_T_FMT "k", (size + 512) / 1024);
644     }
645     else if (size < 103809024) {
646         ap_rprintf(r, "%4.1fM", size / 1048576.0);
647     }
648     else {
649         ap_rprintf(r, "%4" APR_SSIZE_T_FMT "M", (size + 524288) / 1048576);
650     }
651 }
652