dgaudet 98/03/28 03:58:37
Modified: . STATUS src CHANGES src/ap ap_snprintf.c src/include alloc.h ap.h buff.h conf.h src/main Makefile.tmpl alloc.c buff.c http_core.c http_main.c http_protocol.c http_request.c util.c util_script.c src/modules/standard mod_expires.c mod_include.c mod_log_config.c mod_rewrite.c mod_usertrack.c Removed: src/main http_bprintf.c Log: Finally dealt with the vformatter() thing that's been sitting in STATUS since october. - apapi_vformatter() is generic printf-style routine with arbitrary output - replaces ap_snprintf(), eliminate the possibility of HAVE_SNPRINTF - replaces bprintf() and bvprintf() - add new psprintf()/pvsprintf() which allocate the string from the pool -- no static limitations - use psprintf() in a bunch of places Revision Changes Path 1.228 +0 -9 apache-1.3/STATUS Index: STATUS =================================================================== RCS file: /export/home/cvs/apache-1.3/STATUS,v retrieving revision 1.227 retrieving revision 1.228 diff -u -r1.227 -r1.228 --- STATUS 1998/03/27 17:37:26 1.227 +++ STATUS 1998/03/28 11:58:11 1.228 @@ -300,15 +300,6 @@ src/Configure. Just comitting APACI files will not be done. The existing README has to be adjusted. I'll do this. -Concepts: - - * Dean's [PRE-PATCH] expanding ap_snprintf() - <[EMAIL PROTECTED]> - Status: Dean +1, Ben +1, Jim 0, Martin 0, Brian +1(?), Ken +1 - See <[EMAIL PROTECTED]> - for a more up-to-date idea (int vformatter) that has a - vote of +1 from Dean, Ben, Martin, Paul, Jim, and Ken for concept - In progress: * Ken's IndexFormat enhancement to mod_autoindex to allow 1.741 +8 -0 apache-1.3/src/CHANGES Index: CHANGES =================================================================== RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v retrieving revision 1.740 retrieving revision 1.741 diff -u -r1.740 -r1.741 --- CHANGES 1998/03/27 20:18:46 1.740 +++ CHANGES 1998/03/28 11:58:13 1.741 @@ -1,5 +1,13 @@ Changes with Apache 1.3b6 + *) API: ap_snprintf() code mutated into apapi_vformatter(), which is + a generic printf-style routine that can call arbitrary output + routines. Use this to replace http_bprintf.c. Add new routines + psprintf(), pvsprintf() which allocate the exact amount of memory + required for a string from a pool. Use psprintf() to clean up + various bits of code which used ap_snprintf()/pstrdup(). + [Dean Gaudet] + *) SIGXCPU and SIGXFSZ are now reset to SIG_DFL at boot-time. This is necessary on at least Solaris where the /etc/rc?.d scripts are run with these signals ignored, and "SIG_IGN" settings are 1.14 +52 -49 apache-1.3/src/ap/ap_snprintf.c Index: ap_snprintf.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/ap/ap_snprintf.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ap_snprintf.c 1998/02/12 02:18:38 1.13 +++ ap_snprintf.c 1998/03/28 11:58:15 1.14 @@ -54,9 +54,7 @@ * <[EMAIL PROTECTED]> for xinetd. */ -#include "conf.h" - -#ifndef HAVE_SNPRINTF +#include "httpd.h" #include <stdio.h> #include <ctype.h> @@ -264,17 +262,6 @@ */ #define NUM_BUF_SIZE 512 - -/* - * Descriptor for buffer area - */ -struct buf_area { - char *buf_end; - char *nextb; /* pointer to next byte to read/write */ -}; - -typedef struct buf_area buffy; - /* * The INS_CHAR macro inserts a character in the buffer and writes * the buffer back to disk if necessary @@ -285,13 +272,16 @@ * * NOTE: Evaluation of the c argument should not have any side-effects */ -#define INS_CHAR( c, sp, bep, cc ) \ - { \ - if ( sp < bep ) \ - { \ - *sp++ = c ; \ - cc++ ; \ - } \ +#define INS_CHAR(c, sp, bep, cc) \ + { \ + if (sp == bep) { \ + if (write_func(write_data, staging_buf, \ + sizeof(staging_buf)) != 0) \ + return -1; \ + sp = staging_buf; \ + } \ + *sp++ = (c); \ + cc++; \ } #define NUM( c ) ( c - '0' ) @@ -521,8 +511,9 @@ /* * Do format conversion placing the output in buffer */ -static int format_converter(register buffy *odp, const char *fmt, - va_list ap) +API_EXPORT(int) apapi_vformatter( + int (*write_func)(void *, const char *, size_t), + void *write_data, const char *fmt, va_list ap) { register char *sp; register char *bep; @@ -548,6 +539,8 @@ char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ + char staging_buf[MAX_STRING_LEN]; + /* * Flag variables */ @@ -559,8 +552,8 @@ boolean_e adjust_width; bool_int is_negative; - sp = odp->nextb; - bep = odp->buf_end; + sp = staging_buf; + bep = sp + sizeof(staging_buf); while (*fmt) { if (*fmt != '%') { @@ -890,31 +883,33 @@ } fmt++; } - odp->nextb = sp; - return (cc); + if (sp > staging_buf) { + if (write_func(write_data, staging_buf, sp - staging_buf) != 0) { + return -1; + } + } + return cc; } -/* - * This is the general purpose conversion function. - */ -static void strx_printv(int *ccp, char *buf, size_t len, const char *format, - va_list ap) -{ - buffy od; - int cc; +struct snprintf_write_data { + char *strp; + char *end_buf; +}; - /* save 1 byte for nul terminator, we assume len > 0 */ - od.buf_end = &buf[len - 1]; - od.nextb = buf; +static int snprintf_write(void *vdata, const char *inp, size_t len) +{ + struct snprintf_write_data *wd; + size_t amt; - /* - * Do the conversion - */ - cc = format_converter(&od, format, ap); - *(od.nextb) = '\0'; - if (ccp) - *ccp = cc; + wd = vdata; + amt = wd->end_buf - wd->strp; + if (len > amt) { + len = amt; + } + memcpy(wd->strp, inp, len); + wd->strp += len; + return 0; } @@ -922,12 +917,17 @@ { int cc; va_list ap; + struct snprintf_write_data wd; if (len == 0) return 0; + /* save one byte for nul terminator */ + wd.strp = buf; + wd.end_buf = buf + len - 1; va_start(ap, format); - strx_printv(&cc, buf, len, format, ap); + cc = apapi_vformatter(snprintf_write, &wd, format, ap); + *wd.strp = '\0'; va_end(ap); return (cc); } @@ -937,12 +937,15 @@ va_list ap) { int cc; + struct snprintf_write_data wd; if (len == 0) return 0; - strx_printv(&cc, buf, len, format, ap); + /* save one byte for nul terminator */ + wd.strp = buf; + wd.end_buf = buf + len - 1; + cc = apapi_vformatter(snprintf_write, &wd, format, ap); + *wd.strp = '\0'; return (cc); } - -#endif /* HAVE_SNPRINTF */ 1.50 +3 -0 apache-1.3/src/include/alloc.h Index: alloc.h =================================================================== RCS file: /export/home/cvs/apache-1.3/src/include/alloc.h,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- alloc.h 1998/03/17 07:54:10 1.49 +++ alloc.h 1998/03/28 11:58:16 1.50 @@ -117,6 +117,9 @@ /* make a nul terminated copy of the n characters starting with s */ API_EXPORT(char *) pstrndup(struct pool *, const char *s, int n); API_EXPORT(char *) pstrcat(struct pool *,...); /* all '...' must be char* */ +API_EXPORT_NONSTD(char *) psprintf(struct pool *, const char *fmt, ...) + __attribute__((format(printf,2,3))); +API_EXPORT(char *) pvsprintf(struct pool *, const char *fmt, va_list); /* array and alist management... keeping lists of things. * Common enough to want common support code ... 1.8 +23 -0 apache-1.3/src/include/ap.h Index: ap.h =================================================================== RCS file: /export/home/cvs/apache-1.3/src/include/ap.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ap.h 1998/02/14 10:43:19 1.7 +++ ap.h 1998/03/28 11:58:17 1.8 @@ -77,4 +77,27 @@ #endif #endif /* WIN32 */ +/* apapi_vformatter() is a generic printf-style formatting routine + * with some extensions. + * + * The write_func() is called when there is data available to be + * output. write_func() should return 0 when it wishes apapi_vformatter + * to continue, and non-zero otherwise. apapi_vformatter will stop + * immediately and return -1 when a non-zero return from + * write_func(). + * + * If write_func() always returns 0 then apapi_vformatter will return + * the number of characters written. + */ + +API_EXPORT(int) apapi_vformatter( + int (*write_func)(void *write_data, const char *outp, size_t len), + void *write_data, const char *fmt, va_list ap); + +/* These are snprintf implementations based on apapi_vformatter(). */ +API_EXPORT(int) ap_snprintf(char *buf, size_t len, const char *format,...) + __attribute__((format(printf,3,4))); +API_EXPORT(int) ap_vsnprintf(char *buf, size_t len, const char *format, + va_list ap); + #endif /* !APACHE_AP_H */ 1.35 +1 -1 apache-1.3/src/include/buff.h Index: buff.h =================================================================== RCS file: /export/home/cvs/apache-1.3/src/include/buff.h,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- buff.h 1998/02/07 21:54:13 1.34 +++ buff.h 1998/03/28 11:58:17 1.35 @@ -156,7 +156,7 @@ API_EXPORT(int) bvputs(BUFF *fb,...); API_EXPORT_NONSTD(int) bprintf(BUFF *fb, const char *fmt,...) __attribute__((format(printf,2,3))); -API_EXPORT_NONSTD(int) vbprintf(BUFF *fb, const char *fmt, va_list vlist); +API_EXPORT(int) vbprintf(BUFF *fb, const char *fmt, va_list vlist); /* Internal routines */ API_EXPORT(int) bflsbuf(int c, BUFF *fb); 1.196 +0 -14 apache-1.3/src/include/conf.h Index: conf.h =================================================================== RCS file: /export/home/cvs/apache-1.3/src/include/conf.h,v retrieving revision 1.195 retrieving revision 1.196 diff -u -r1.195 -r1.196 --- conf.h 1998/03/26 19:26:25 1.195 +++ conf.h 1998/03/28 11:58:19 1.196 @@ -806,20 +806,6 @@ #include <sys/types.h> #include <stdarg.h> -/* - * We use snprintf() to avoid overflows, but we include - * our own version (ap_snprintf). Allow for people to use their - * snprintf() if they want - */ -#ifdef HAVE_SNPRINTF -#define ap_snprintf snprintf -#define ap_vsnprintf vsnprintf -#else -API_EXPORT(int) ap_snprintf(char *buf, size_t len, const char *format,...) - __attribute__((format(printf,3,4))); -API_EXPORT(int) ap_vsnprintf(char *buf, size_t len, const char *format, - va_list ap); -#endif #if !defined(NEXT) && !defined(WIN32) #include <dirent.h> 1.22 +1 -9 apache-1.3/src/main/Makefile.tmpl Index: Makefile.tmpl =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/Makefile.tmpl,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- Makefile.tmpl 1998/03/27 10:06:53 1.21 +++ Makefile.tmpl 1998/03/28 11:58:21 1.22 @@ -11,7 +11,7 @@ LIB= libmain.a OBJS= alloc.o buff.o \ - http_bprintf.o http_config.o http_core.o http_log.o \ + http_config.o http_core.o http_log.o \ http_main.o http_protocol.o http_request.o http_vhost.o \ util.o util_date.o util_script.o util_uri.o util_md5.o \ md5c.o rfc1413.o fnmatch.o @@ -29,10 +29,6 @@ clean: rm -f *.o $(LIB) uri_delims.h gen_uri_delims test_char.h gen_test_char -# Work around broken compilers -http_bprintf.o: http_bprintf.c - $(CC) -c $(INCLUDES) $(CFLAGS) $(BROKEN_BPRINTF_FLAGS) http_bprintf.c - uri_delims.h: gen_uri_delims ./gen_uri_delims >uri_delims.h @@ -76,10 +72,6 @@ $(INCDIR)/alloc.h $(INCDIR)/buff.h $(INCDIR)/ap.h \ $(INCDIR)/util_uri.h gen_uri_delims.o: gen_uri_delims.c -http_bprintf.o: http_bprintf.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ - ../os/unix/os.h $(INCDIR)/hide.h $(INCDIR)/hsregex.h \ - $(INCDIR)/alloc.h $(INCDIR)/buff.h $(INCDIR)/ap.h \ - $(INCDIR)/util_uri.h http_config.o: http_config.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ ../os/unix/os.h $(INCDIR)/hide.h $(INCDIR)/hsregex.h \ $(INCDIR)/alloc.h $(INCDIR)/buff.h $(INCDIR)/ap.h \ 1.80 +112 -5 apache-1.3/src/main/alloc.c Index: alloc.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/alloc.c,v retrieving revision 1.79 retrieving revision 1.80 diff -u -r1.79 -r1.80 --- alloc.c 1998/03/17 08:20:55 1.79 +++ alloc.c 1998/03/28 11:58:21 1.80 @@ -198,7 +198,7 @@ static union block_hdr *malloc_block(int size) { union block_hdr *blok = - (union block_hdr *) malloc(size + sizeof(union block_hdr)); + (union block_hdr *) malloc(size + sizeof(union block_hdr)); if (blok == NULL) { fprintf(stderr, "Ouch! malloc failed in malloc_block()\n"); @@ -456,10 +456,8 @@ block_alarms(); (void) acquire_mutex(alloc_mutex); - { while (a->sub_pools) destroy_pool(a->sub_pools); - } (void) release_mutex(alloc_mutex); /* Don't hold the mutex during cleanups. */ run_cleanups(a->cleanups); @@ -495,7 +493,6 @@ clear_pool(a); (void) acquire_mutex(alloc_mutex); - { if (a->parent) { if (a->parent->sub_pools == a) a->parent->sub_pools = a->sub_next; @@ -504,7 +501,6 @@ if (a->sub_next) a->sub_next->sub_prev = a->sub_prev; } - } (void) release_mutex(alloc_mutex); free_blocks(a->first); @@ -775,6 +771,117 @@ return res; } +/* XXX */ +#ifdef ALLOC_USE_MALLOC +#error "psprintf does not support ALLOC_USE_MALLOC yet..." +#endif + +/* psprintf is implemented by writing directly into the current + * block of the pool, starting right at first_avail. If there's + * insufficient room, then a new block is allocated and the earlier + * output is copied over. The new block isn't linked into the pool + * until all the output is done. + */ + +struct psprintf_data { + pool *p; + union block_hdr *blok; + char *strp; + int got_a_new_block; +}; + +static int psprintf_write(void *vdata, const char *inp, size_t len) +{ + struct psprintf_data *ps; + union block_hdr *blok; + union block_hdr *nblok; + size_t cur_len; + char *strp; + + ps = vdata; + + /* does it fit in the current block? */ + blok = ps->blok; + strp = ps->strp; + if (strp + len + 1 < blok->h.endp) { + memcpy(strp, inp, len); + ps->strp = strp + len; + return 0; + } + + cur_len = strp - blok->h.first_avail; + + /* must try another blok */ + block_alarms(); + (void) acquire_mutex(alloc_mutex); + nblok = new_block((cur_len + len)*2); + (void) release_mutex(alloc_mutex); + unblock_alarms(); + strp = nblok->h.first_avail; + memcpy(strp, blok->h.first_avail, cur_len); + strp += cur_len; + memcpy(strp, inp, len); + strp += len; + ps->strp = strp; + + /* did we allocate the current blok? if so free it up */ + if (ps->got_a_new_block) { + debug_fill(blok->h.first_avail, blok->h.endp - blok->h.first_avail); + block_alarms(); + (void) acquire_mutex(alloc_mutex); + blok->h.next = block_freelist; + block_freelist = blok; + (void) release_mutex(alloc_mutex); + unblock_alarms(); + } + ps->blok = nblok; + ps->got_a_new_block = 1; + return 0; +} + +API_EXPORT(char *) pvsprintf(pool *p, const char *fmt, va_list ap) +{ + struct psprintf_data ps; + char *strp; + int size; + + ps.p = p; + ps.blok = p->last; + ps.strp = ps.blok->h.first_avail; + ps.got_a_new_block = 0; + + apapi_vformatter(psprintf_write, &ps, fmt, ap); + + strp = ps.strp; + *strp++ = '\0'; + + size = strp - ps.blok->h.first_avail; + size = (1 + ((size - 1) / CLICK_SZ)) * CLICK_SZ; + strp = ps.blok->h.first_avail; /* save away result pointer */ + ps.blok->h.first_avail += size; + + /* have to link the block in if it's a new one */ + if (ps.got_a_new_block) { + p->last->h.next = ps.blok; + p->last = ps.blok; +#ifdef POOL_DEBUG + ps.blok->h.owning_pool = p; +#endif + } + + return strp; +} + +API_EXPORT_NONSTD(char *) psprintf(pool *p, const char *fmt, ...) +{ + va_list ap; + char *res; + + va_start(ap, fmt); + res = pvsprintf(p, fmt, ap); + va_end(ap); + return res; +} /***************************************************************** * 1.67 +24 -0 apache-1.3/src/main/buff.c Index: buff.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/buff.c,v retrieving revision 1.66 retrieving revision 1.67 diff -u -r1.66 -r1.67 --- buff.c 1998/03/25 02:57:22 1.66 +++ buff.c 1998/03/28 11:58:22 1.67 @@ -1444,3 +1444,27 @@ fb->error = error; fb->error_data = data; } + +static int bprintf_write(void *vdata, const char *inp, size_t len) +{ + if (bwrite(vdata, inp, len) != len) { + return -1; + } + return 0; +} + +API_EXPORT_NONSTD(int) bprintf(BUFF *fb, const char *fmt, ...) +{ + va_list ap; + int res; + + va_start(ap, fmt); + res = apapi_vformatter(bprintf_write, fb, fmt, ap); + va_end(ap); + return res; +} + +API_EXPORT(int) vbprintf(BUFF *fb, const char *fmt, va_list ap) +{ + return apapi_vformatter(bprintf_write, fb, fmt, ap); +} 1.178 +3 -10 apache-1.3/src/main/http_core.c Index: http_core.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_core.c,v retrieving revision 1.177 retrieving revision 1.178 diff -u -r1.177 -r1.178 --- http_core.c 1998/03/26 21:20:49 1.177 +++ http_core.c 1998/03/28 11:58:23 1.178 @@ -614,7 +614,6 @@ { unsigned port; const char *host; - char portnum[22]; core_dir_config *d = (core_dir_config *)get_module_config(r->per_dir_config, &core_module); @@ -635,8 +634,7 @@ if (is_default_port(port, r)) { return pstrcat(p, http_method(r), "://", host, uri, NULL); } - ap_snprintf(portnum, sizeof(portnum), "%u", port); - return pstrcat(p, http_method(r), "://", host, ":", portnum, uri, NULL); + return psprintf(p, "%s://%s:%u%s", http_method(r), host, port, uri); } /***************************************************************** @@ -921,16 +919,11 @@ */ static const char *missing_endsection (cmd_parms *cmd, int nest) { - char rply[100]; - if (nest < 2) - ap_snprintf(rply, sizeof rply, "Missing %s directive at end-of-file", + return psprintf(cmd->pool, "Missing %s directive at end-of-file", cmd->end_token); - else - ap_snprintf(rply, sizeof rply, "%d missing %s directives at end-of-file", + return psprintf(cmd->pool, "%d missing %s directives at end-of-file", nest, cmd->end_token); - - return pstrdup(cmd->pool, rply); } /* We use this in <DirectoryMatch> and <FilesMatch>, to ensure that 1.316 +17 -19 apache-1.3/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_main.c,v retrieving revision 1.315 retrieving revision 1.316 diff -u -r1.315 -r1.316 --- http_main.c 1998/03/27 20:18:50 1.315 +++ http_main.c 1998/03/28 11:58:24 1.316 @@ -337,11 +337,9 @@ #if defined(USE_FCNTL_SERIALIZED_ACCEPT) || defined(USE_FLOCK_SERIALIZED_ACCEPT) static void expand_lock_fname(pool *p) { - char buf[20]; - /* XXXX possibly bogus cast */ - ap_snprintf(buf, sizeof(buf), ".%lu", (unsigned long)getpid()); - lock_fname = pstrcat(p, server_root_relative(p, lock_fname), buf, NULL); + lock_fname = psprintf(p, "%s.%lu", + server_root_relative(p, lock_fname), (unsigned long)getpid()); } #endif @@ -816,7 +814,6 @@ static void timeout(int sig) { /* Also called on SIGPIPE */ - char errstr[MAX_STRING_LEN]; void *dirconf; signal(SIGPIPE, SIG_IGN); /* Block SIGPIPE */ @@ -836,21 +833,22 @@ dirconf = timeout_req->per_dir_config; else dirconf = current_conn->server->lookup_defaults; - if (sig == SIGPIPE) { - ap_snprintf(errstr, sizeof(errstr), - "%s client stopped connection before %s completed", - get_remote_host(current_conn, dirconf, REMOTE_NAME), - timeout_name ? timeout_name : "request"); - } - else { - ap_snprintf(errstr, sizeof(errstr), "%s timed out for %s", - timeout_name ? timeout_name : "request", - get_remote_host(current_conn, dirconf, REMOTE_NAME)); + if (!current_conn->keptalive) { + if (sig == SIGPIPE) { + aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, + current_conn->server, + "%s client stopped connection before %s completed", + get_remote_host(current_conn, dirconf, REMOTE_NAME), + timeout_name ? timeout_name : "request"); + } + else { + aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, + current_conn->server, + "%s timed out for %s", + timeout_name ? timeout_name : "request", + get_remote_host(current_conn, dirconf, REMOTE_NAME)); + } } - - if (!current_conn->keptalive) - aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, - current_conn->server, errstr); if (timeout_req) { /* Someone has asked for this transaction to just be aborted 1.204 +27 -35 apache-1.3/src/main/http_protocol.c Index: http_protocol.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_protocol.c,v retrieving revision 1.203 retrieving revision 1.204 diff -u -r1.203 -r1.204 --- http_protocol.c 1998/03/25 10:07:55 1.203 +++ http_protocol.c 1998/03/28 11:58:26 1.204 @@ -118,7 +118,6 @@ API_EXPORT(int) set_byterange(request_rec *r) { char *range, *if_range, *match; - char ts[MAX_STRING_LEN]; long range_start, range_end; if (!r->clength || r->assbackwards) @@ -163,25 +162,23 @@ r->byterange = 1; - ap_snprintf(ts, sizeof(ts), "bytes %ld-%ld/%ld", - range_start, range_end, r->clength); - table_setn(r->headers_out, "Content-Range", pstrdup(r->pool, ts)); - ap_snprintf(ts, sizeof(ts), "%ld", range_end - range_start + 1); - table_setn(r->headers_out, "Content-Length", pstrdup(r->pool, ts)); + table_setn(r->headers_out, "Content-Range", + psprintf(r->pool, "bytes %ld-%ld/%ld", + range_start, range_end, r->clength)); + table_setn(r->headers_out, "Content-Length", + psprintf(r->pool, "%ld", range_end - range_start + 1)); } else { /* a multiple range */ - char boundary[33]; /* Long enough */ char *r_range = pstrdup(r->pool, range + 6); long tlength = 0; r->byterange = 2; - ap_snprintf(boundary, sizeof(boundary), "%lx%lx", - r->request_time, (long) getpid()); - r->boundary = pstrdup(r->pool, boundary); + r->boundary = psprintf(r->pool, "%lx%lx", + r->request_time, (long) getpid()); while (internal_byterange(0, &tlength, r, &r_range, NULL, NULL)); - ap_snprintf(ts, sizeof(ts), "%ld", tlength); - table_setn(r->headers_out, "Content-Length", pstrdup(r->pool, ts)); + table_setn(r->headers_out, "Content-Length", + psprintf(r->pool, "%ld", tlength)); } r->status = PARTIAL_CONTENT; @@ -254,13 +251,8 @@ API_EXPORT(int) set_content_length(request_rec *r, long clength) { - char ts[MAX_STRING_LEN]; - r->clength = clength; - - ap_snprintf(ts, sizeof(ts), "%ld", clength); - table_setn(r->headers_out, "Content-Length", pstrdup(r->pool, ts)); - + table_setn(r->headers_out, "Content-Length", psprintf(r->pool, "%ld", clength)); return 0; } @@ -317,7 +309,6 @@ ((ka_sent = find_token(r->pool, conn, "keep-alive")) || (r->proto_num >= HTTP_VERSION(1,1))) ) { - char header[256]; int left = r->server->keep_alive_max - r->connection->keepalives; r->connection->keepalive = 1; @@ -326,12 +317,13 @@ /* If they sent a Keep-Alive token, send one back */ if (ka_sent) { if (r->server->keep_alive_max) - ap_snprintf(header, sizeof(header), "timeout=%d, max=%d", - r->server->keep_alive_timeout, left); + table_setn(r->headers_out, "Keep-Alive", + psprintf(r->pool, "timeout=%d, max=%d", + r->server->keep_alive_timeout, left)); else - ap_snprintf(header, sizeof(header), "timeout=%d", - r->server->keep_alive_timeout); - table_setn(r->headers_out, "Keep-Alive", pstrdup(r->pool, header)); + table_setn(r->headers_out, "Keep-Alive", + psprintf(r->pool, "timeout=%d", + r->server->keep_alive_timeout)); table_mergen(r->headers_out, "Connection", "Keep-Alive"); } @@ -475,7 +467,8 @@ */ API_EXPORT(void) set_etag(request_rec *r) { - char *etag, weak_etag[MAX_STRING_LEN]; + char *etag; + char *weak; /* * Make an ETag header out of various pieces of information. We use @@ -489,20 +482,22 @@ * be modified again later in the second, and the validation * would be incorrect. */ + + weak = (r->request_time - r->mtime > 1) ? "" : "W/"; if (r->finfo.st_mode != 0) { - ap_snprintf(weak_etag, sizeof(weak_etag), "W/\"%lx-%lx-%lx\"", + etag = psprintf(r->pool, + "%s\"%lx-%lx-%lx\"", weak, (unsigned long) r->finfo.st_ino, (unsigned long) r->finfo.st_size, (unsigned long) r->mtime); } else { - ap_snprintf(weak_etag, sizeof(weak_etag), "W/\"%lx\"", + etag = psprintf(r->pool, "%s\"%lx\"", weak, (unsigned long) r->mtime); } - etag = weak_etag + ((r->request_time - r->mtime > 1) ? 2 : 0); - table_setn(r->headers_out, "ETag", pstrdup(r->pool, etag)); + table_setn(r->headers_out, "ETag", etag); } /* @@ -860,13 +855,10 @@ API_EXPORT(void) note_digest_auth_failure(request_rec *r) { - char nonce[256]; - - ap_snprintf(nonce, sizeof(nonce), "%lu", r->request_time); table_setn(r->err_headers_out, - r->proxyreq ? "Proxy-Authenticate" : "WWW-Authenticate", - pstrcat(r->pool, "Digest realm=\"", auth_name(r), - "\", nonce=\"", nonce, "\"", NULL)); + r->proxyreq ? "Proxy-Authenticate" : "WWW-Authenticate", + psprintf(r->pool, "Digest realm=\"%s\", nonce=\"%lu\"", + auth_name(r), r->request_time)); } API_EXPORT(int) get_basic_auth_pw(request_rec *r, char **pw) 1.115 +2 -3 apache-1.3/src/main/http_request.c Index: http_request.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_request.c,v retrieving revision 1.114 retrieving revision 1.115 diff -u -r1.114 -r1.115 --- http_request.c 1998/03/26 14:06:48 1.114 +++ http_request.c 1998/03/28 11:58:26 1.115 @@ -1205,7 +1205,6 @@ { int access_status; request_rec *new = (request_rec *) pcalloc(r->pool, sizeof(request_rec)); - char t[256]; /* Long enough... */ new->connection = r->connection; new->server = r->server; @@ -1252,8 +1251,8 @@ new->no_local_copy = r->no_local_copy; new->read_length = r->read_length; /* We can only read it once */ - ap_snprintf(t, sizeof(t), "%d", r->status); - table_setn(new->subprocess_env, "REDIRECT_STATUS", pstrdup(r->pool, t)); + table_setn(new->subprocess_env, "REDIRECT_STATUS", + psprintf(r->pool, "%d", r->status)); /* * XXX: hmm. This is because mod_setenvif and mod_unique_id really need 1.109 +2 -9 apache-1.3/src/main/util.c Index: util.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/util.c,v retrieving revision 1.108 retrieving revision 1.109 diff -u -r1.108 -r1.109 --- util.c 1998/03/26 04:58:40 1.108 +++ util.c 1998/03/28 11:58:27 1.109 @@ -130,18 +130,15 @@ API_EXPORT(char *) gm_timestr_822(pool *p, time_t sec) { - char ts[50]; struct tm *tms; tms = gmtime(&sec); /* RFC date format; as strftime '%a, %d %b %Y %T GMT' */ - ap_snprintf(ts, sizeof(ts), + return psprintf(p, "%s, %.2d %s %d %.2d:%.2d:%.2d GMT", day_snames[tms->tm_wday], tms->tm_mday, month_snames[tms->tm_mon], tms->tm_year + 1900, tms->tm_hour, tms->tm_min, tms->tm_sec); - - return pstrdup(p, ts); } /* What a pain in the ass. */ @@ -1086,14 +1083,10 @@ API_EXPORT(char *) construct_server(pool *p, const char *hostname, unsigned port, const request_rec *r) { - char portnum[22]; - /* Long enough, even if port > 16 bits for some reason */ - if (is_default_port(port, r)) return pstrdup(p, hostname); else { - ap_snprintf(portnum, sizeof(portnum), "%u", port); - return pstrcat(p, hostname, ":", portnum, NULL); + return psprintf(p, "%s:%u", hostname, port); } } 1.104 +9 -14 apache-1.3/src/main/util_script.c Index: util_script.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/util_script.c,v retrieving revision 1.103 retrieving revision 1.104 diff -u -r1.103 -r1.104 --- util_script.c 1998/03/14 00:50:39 1.103 +++ util_script.c 1998/03/28 11:58:28 1.104 @@ -183,7 +183,7 @@ server_rec *s = r->server; conn_rec *c = r->connection; const char *rem_logname; - char port[40], *env_path; + char *env_path; #ifdef WIN32 char *env_temp; #endif @@ -240,8 +240,7 @@ table_setn(e, "PATH", env_path); table_setn(e, "SERVER_SOFTWARE", apapi_get_server_version()); table_setn(e, "SERVER_NAME", get_server_name(r)); - ap_snprintf(port, sizeof(port), "%u", get_server_port(r)); - table_setn(e, "SERVER_PORT", pstrdup(r->pool,port)); + table_setn(e, "SERVER_PORT", psprintf(r->pool, "%u", get_server_port(r))); host = get_remote_host(c, r->per_dir_config, REMOTE_HOST); if (host) { table_setn(e, "REMOTE_HOST", host); @@ -251,8 +250,7 @@ table_setn(e, "SERVER_ADMIN", s->server_admin); /* Apache */ table_setn(e, "SCRIPT_FILENAME", r->filename); /* Apache */ - ap_snprintf(port, sizeof(port), "%d", ntohs(c->remote_addr.sin_port)); - table_setn(e, "REMOTE_PORT", pstrdup(r->pool, port)); /* Apache */ + table_setn(e, "REMOTE_PORT", psprintf(r->pool, "%d", ntohs(c->remote_addr.sin_port))); if (c->user) table_setn(e, "REMOTE_USER", c->user); @@ -542,22 +540,19 @@ API_EXPORT(void) send_size(size_t size, request_rec *r) { - char ss[20]; - /* XXX: this -1 thing is a gross hack */ if (size == (size_t)-1) - strcpy(ss, " -"); + rputs(" -", r); else if (!size) - strcpy(ss, " 0k"); + rputs(" 0k", r); else if (size < 1024) - strcpy(ss, " 1k"); + rputs(" 1k", r); else if (size < 1048576) - ap_snprintf(ss, sizeof(ss), "%4dk", (size + 512) / 1024); + rprintf(r, "%4dk", (size + 512) / 1024); else if (size < 103809024) - ap_snprintf(ss, sizeof(ss), "%4.1fM", size / 1048576.0); + rprintf(r, "%4.1fM", size / 1048576.0); else - ap_snprintf(ss, sizeof(ss), "%4dM", (size + 524288) / 1048576); - rputs(ss, r); + rprintf(r, "%4dM", (size + 524288) / 1048576); } #if defined(__EMX__) || defined(WIN32) 1.25 +1 -3 apache-1.3/src/modules/standard/mod_expires.c Index: mod_expires.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_expires.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- mod_expires.c 1998/03/13 19:20:34 1.24 +++ mod_expires.c 1998/03/28 11:58:32 1.25 @@ -242,7 +242,6 @@ int modifier = 0; int num = 0; int factor = 0; - char foo[MAX_STRING_LEN]; /* 0.0.4 compatibility? */ @@ -333,8 +332,7 @@ word = getword_conf(p, &code); }; - ap_snprintf(foo, sizeof(foo), "%c%d", base, modifier); - *real_code = pstrdup(p, foo); + *real_code = psprintf(p, "%c%d", base, modifier); return NULL; } 1.78 +2 -4 apache-1.3/src/modules/standard/mod_include.c Index: mod_include.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_include.c,v retrieving revision 1.77 retrieving revision 1.78 diff -u -r1.77 -r1.78 --- mod_include.c 1998/03/18 04:11:19 1.77 +++ mod_include.c 1998/03/28 11:58:32 1.78 @@ -130,10 +130,8 @@ table_setn(e, "USER_NAME", pstrdup(r->pool, pw->pw_name)); } else { - char uid[16]; - ap_snprintf(uid, sizeof(uid), "user#%lu", - (unsigned long) r->finfo.st_uid); - table_setn(e, "USER_NAME", pstrdup(r->pool, uid)); + table_setn(e, "USER_NAME", psprintf(r->pool, "user#%lu", + (unsigned long) r->finfo.st_uid)); } #endif /* ndef WIN32 */ 1.51 +5 -18 apache-1.3/src/modules/standard/mod_log_config.c Index: mod_log_config.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_log_config.c,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- mod_log_config.c 1998/03/15 23:21:42 1.50 +++ mod_log_config.c 1998/03/28 11:58:33 1.51 @@ -251,9 +251,7 @@ static char *format_integer(pool *p, int i) { - char dummy[40]; - ap_snprintf(dummy, sizeof(dummy), "%d", i); - return pstrdup(p, dummy); + return psprintf(p, "%d", i); } static char *pfmt(pool *p, int i) @@ -333,10 +331,8 @@ } else { long int bs; - char dummy[40]; bgetopt(r->connection->client, BO_BYTECT, &bs); - ap_snprintf(dummy, sizeof(dummy), "%ld", bs); - return pstrdup(r->pool, dummy); + return psprintf(r->pool, "%ld", bs); } } @@ -394,11 +390,7 @@ static char *log_request_duration(request_rec *r, char *a) { - char duration[22]; /* Long enough for 2^64 */ - - ap_snprintf(duration, sizeof(duration), "%ld", - time(NULL) - r->request_time); - return pstrdup(r->pool, duration); + return psprintf(r->pool, "%ld", time(NULL) - r->request_time); } /* These next two routines use the canonical name:port so that log @@ -411,17 +403,12 @@ static char *log_server_port(request_rec *r, char *a) { - char portnum[22]; - - ap_snprintf(portnum, sizeof(portnum), "%u", r->server->port); - return pstrdup(r->pool, portnum); + return psprintf(r->pool, "%u", r->server->port); } static char *log_child_pid(request_rec *r, char *a) { - char pidnum[22]; - ap_snprintf(pidnum, sizeof(pidnum), "%ld", (long) getpid()); - return pstrdup(r->pool, pidnum); + return psprintf(r->pool, "%ld", (long) getpid()); } /***************************************************************** 1.97 +3 -6 apache-1.3/src/modules/standard/mod_rewrite.c Index: mod_rewrite.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v retrieving revision 1.96 retrieving revision 1.97 diff -u -r1.96 -r1.97 --- mod_rewrite.c 1998/03/27 17:37:38 1.96 +++ mod_rewrite.c 1998/03/28 11:58:34 1.97 @@ -999,7 +999,7 @@ thisport = ""; else { ap_snprintf(buf, sizeof(buf), ":%u", r->server->port); - thisport = pstrdup(r->pool, buf); + thisport = buf; } thisurl = table_get(r->subprocess_env, ENVVAR_SCRIPT_URL); @@ -2246,7 +2246,6 @@ static void fully_qualify_uri(request_rec *r) { int i; - char newuri[MAX_STRING_LEN]; char port[32]; i = strlen(r->filename); @@ -2261,15 +2260,13 @@ ap_snprintf(port, sizeof(port), ":%u", r->server->port); if (r->filename[0] == '/') - ap_snprintf(newuri, sizeof(newuri), "%s://%s%s%s", + r->filename = psprintf(r->pool, "%s://%s%s%s", http_method(r), r->server->server_hostname, port, r->filename); else - ap_snprintf(newuri, sizeof(newuri), "%s://%s%s/%s", + r->filename = psprintf(r->pool, "%s://%s%s/%s", http_method(r), r->server->server_hostname, port, r->filename); - - r->filename = pstrdup(r->pool, newuri); } return; } 1.31 +8 -8 apache-1.3/src/modules/standard/mod_usertrack.c Index: mod_usertrack.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_usertrack.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- mod_usertrack.c 1998/03/14 00:52:48 1.30 +++ mod_usertrack.c 1998/03/28 11:58:35 1.31 @@ -131,9 +131,9 @@ struct timeval tv; struct timezone tz = {0, 0}; #endif - /* 1024 == hardcoded constants */ - char new_cookie[1024]; + /* 1024 == hardcoded constant */ char cookiebuf[1024]; + char *new_cookie; char *dot; const char *rname = get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME); @@ -148,7 +148,7 @@ mpe_times = times(&mpe_tms); - ap_snprintf(cookiebuf, 1024, "%s%d%ld%ld", rname, (int) getpid(), + ap_snprintf(cookiebuf, sizeof(cookiebuf), "%s%d%ld%ld", rname, (int) getpid(), (long) r->request_time, (long) mpe_tms.tms_utime); #elif defined(WIN32) /* @@ -157,13 +157,13 @@ * was started. It should be relatively unique. */ - ap_snprintf(cookiebuf, 1024, "%s%d%ld%ld", rname, (int) getpid(), + ap_snprintf(cookiebuf, sizeof(cookiebuf), "%s%d%ld%ld", rname, (int) getpid(), (long) r->request_time, (long) GetTickCount()); #else gettimeofday(&tv, &tz); - ap_snprintf(cookiebuf, 1024, "%s%d%ld%d", rname, (int) getpid(), + ap_snprintf(cookiebuf, sizeof(cookiebuf), "%s%d%ld%d", rname, (int) getpid(), (long) tv.tv_sec, (int) tv.tv_usec / 1000); #endif @@ -184,7 +184,7 @@ tms = gmtime(&when); /* Cookie with date; as strftime '%a, %d-%h-%y %H:%M:%S GMT' */ - ap_snprintf(new_cookie, 1024, + new_cookie = psprintf(r->pool, "%s%s; path=/; expires=%s, %.2d-%s-%.2d %.2d:%.2d:%.2d GMT", COOKIE_NAME, cookiebuf, day_snames[tms->tm_wday], tms->tm_mday, month_snames[tms->tm_mon], @@ -192,9 +192,9 @@ tms->tm_hour, tms->tm_min, tms->tm_sec); } else - ap_snprintf(new_cookie, 1024, "%s%s; path=/", COOKIE_NAME, cookiebuf); + new_cookie = psprintf(r->pool, "%s%s; path=/", COOKIE_NAME, cookiebuf); - table_setn(r->headers_out, "Set-Cookie", pstrdup(r->pool, new_cookie)); + table_setn(r->headers_out, "Set-Cookie", new_cookie); table_setn(r->notes, "cookie", pstrdup(r->pool, cookiebuf)); /* log first time */ return; }