1818#include "util_fcgi.h"
1919#include "util_script.h"
2020#include "ap_expr.h"
21- #include <ctype.h>
21+ #include "util_varbuf.h"
2222
2323module AP_MODULE_DECLARE_DATA proxy_fcgi_module ;
2424
@@ -594,71 +594,6 @@ static int handle_headers(request_rec *r, int *state,
594594 return 0 ;
595595}
596596
597- /**
598- * @struct ap_varbuf
599- * @brief Structure representing a dynamically resizable buffer.
600- *
601- * This structure holds a character buffer along with its current length and the total
602- * allocated size. The buffer is allocated from the provided APR pool.
603- */
604- typedef struct {
605- char * buf ;
606- apr_size_t cur_len ;
607- apr_size_t size ;
608- apr_pool_t * pool ;
609- } ap_varbuf ;
610-
611- /**
612- * @brief Allocate and initialize a new dynamic variable buffer.
613- *
614- * This function creates a new ap_varbuf structure, allocates an initial buffer
615- * of the specified size from the given APR pool, and initializes its members.
616- *
617- * @param vb A pointer to the pointer that will hold the allocated ap_varbuf.
618- * @param p The APR memory pool from which to allocate the buffer.
619- * @param initial_size The initial size in bytes for the buffer.
620- * @return APR_SUCCESS on success.
621- */
622- static apr_status_t ap_varbuf_make (ap_varbuf * * vb , apr_pool_t * p , apr_size_t initial_size )
623- {
624- * vb = apr_pcalloc (p , sizeof (ap_varbuf ));
625- (* vb )-> pool = p ;
626- (* vb )-> buf = apr_palloc (p , initial_size );
627- (* vb )-> size = initial_size ;
628- (* vb )-> cur_len = 0 ;
629- (* vb )-> buf [0 ] = '\0' ;
630- return APR_SUCCESS ;
631- }
632-
633-
634- /**
635- * @brief Append a specified number of characters to a dynamic variable buffer.
636- *
637- * This function appends up to @c len characters from the string @c str to the
638- * dynamic buffer represented by @c vb. If the buffer is not large enough to hold
639- * the additional characters plus a null terminator, the function reallocates the
640- * buffer with a larger size. The buffer is always null-terminated after the operation.
641- *
642- * @param vb The dynamic variable buffer to which the string will be appended.
643- * @param str The string containing the characters to append.
644- * @param len The number of characters from @c str to append.
645- * @return APR_SUCCESS on success.
646- */
647- static apr_status_t ap_varbuf_strncat (ap_varbuf * vb , const char * str , apr_size_t len )
648- {
649- if (vb -> cur_len + len + 1 > vb -> size ) {
650- apr_size_t new_size = vb -> cur_len + len + 1 ;
651- char * newbuf = apr_palloc (vb -> pool , new_size );
652- memcpy (newbuf , vb -> buf , vb -> cur_len );
653- vb -> buf = newbuf ;
654- vb -> size = new_size ;
655- }
656- memcpy (vb -> buf + vb -> cur_len , str , len );
657- vb -> cur_len += len ;
658- vb -> buf [vb -> cur_len ] = '\0' ;
659- return APR_SUCCESS ;
660- }
661-
662597
663598static apr_status_t dispatch (proxy_conn_rec * conn , proxy_dir_conf * conf ,
664599 request_rec * r , apr_pool_t * setaside_pool ,
@@ -896,18 +831,18 @@ static apr_status_t dispatch(proxy_conn_rec *conn, proxy_dir_conf *conf,
896831 /* Try our dynamic header buffer approach first */
897832 ap_varbuf_strncat (header_vb , iobuf , readbuflen );
898833 if (strstr (header_vb -> buf , "\r\n\r\n" ) != NULL ) {
899- while (header_vb -> cur_len > 0 &&
834+ while (header_vb -> strlen > 0 &&
900835 isspace ((unsigned char )header_vb -> buf [0 ])) {
901- memmove (header_vb -> buf , header_vb -> buf + 1 , header_vb -> cur_len - 1 );
902- header_vb -> cur_len -- ;
903- header_vb -> buf [header_vb -> cur_len ] = '\0' ;
836+ memmove (header_vb -> buf , header_vb -> buf + 1 , header_vb -> strlen - 1 );
837+ header_vb -> strlen -- ;
838+ header_vb -> buf [header_vb -> strlen ] = '\0' ;
904839 }
905840 seen_end_of_headers = 1 ;
906841 {
907842 int status_hdr ;
908843 apr_bucket_brigade * tmp_bb = apr_brigade_create (r -> pool , c -> bucket_alloc );
909844 apr_bucket * hdr_bucket = apr_bucket_heap_create (header_vb -> buf ,
910- header_vb -> cur_len , NULL , c -> bucket_alloc );
845+ header_vb -> strlen , NULL , c -> bucket_alloc );
911846 APR_BRIGADE_INSERT_TAIL (tmp_bb , hdr_bucket );
912847 hdr_bucket = apr_bucket_eos_create (c -> bucket_alloc );
913848 APR_BRIGADE_INSERT_TAIL (tmp_bb , hdr_bucket );
@@ -921,7 +856,7 @@ static apr_status_t dispatch(proxy_conn_rec *conn, proxy_dir_conf *conf,
921856 }
922857 {
923858 char * hdr_end = strstr (header_vb -> buf , "\r\n\r\n" ) + 4 ;
924- apr_size_t hdr_total = header_vb -> cur_len ;
859+ apr_size_t hdr_total = header_vb -> strlen ;
925860 apr_size_t remaining = hdr_total - (hdr_end - header_vb -> buf );
926861 if (remaining > 0 ) {
927862 apr_bucket * rem_bucket = apr_bucket_heap_create (hdr_end ,
0 commit comments