[PHP-DEV] CVS update: php3/functions From: cschneid (php-dev <email protected>)
Date: 10/25/98

Date: Sunday October 25, 1998 @ 16:34
Author: cschneid

Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv16428/functions

Modified Files:
        head.c head.h
Log Message:
Added zlib compression to output functions of Apache module. This means
(currently for Apache module only) PHP supports the HTTP header line
Accept-encoding: *gzip* and sends Content-encoding: gzip as well as
compressing the output. Added the configuration flag compress_output [on|off]
which can be set for the Apache module on a per directory basis.

Index: php3/functions/head.c
diff -c php3/functions/head.c:1.107 php3/functions/head.c:1.108
*** php3/functions/head.c:1.107 Tue Aug 18 08:49:29 1998
--- php3/functions/head.c Sun Oct 25 16:34:52 1998
***************
*** 26,32 ****
     | Authors: Rasmus Lerdorf <rasmus <email protected>> |
     +----------------------------------------------------------------------+
   */
! /* $Id: head.c,v 1.107 1998/08/18 12:49:29 rasmus Exp $ */
  #ifdef THREAD_SAFE
  #include "tls.h"
  #endif
--- 26,32 ----
     | Authors: Rasmus Lerdorf <rasmus <email protected>> |
     +----------------------------------------------------------------------+
   */
! /* $Id: head.c,v 1.108 1998/10/25 21:34:52 cschneid Exp $ */
  #ifdef THREAD_SAFE
  #include "tls.h"
  #endif
***************
*** 86,91 ****
--- 86,103 ----
  /* Implementation of the language Header() function */
  void php3_Header(INTERNAL_FUNCTION_PARAMETERS)
  {
+ pval *arg1;
+ TLS_VARS;
+
+ if (getParameters(ht, 1, &arg1) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string(arg1);
+ php3_addheaderline(arg1->value.str.val);
+ }
+
+ PHPAPI void php3_addheaderline(char *headerline)
+ {
          char *r;
  #if APACHE
          char *rr = NULL;
***************
*** 93,107 ****
          long myuid = 0L;
          char temp2[32];
  #endif
- pval *arg1;
  TLS_VARS;
  
-
-
- if (getParameters(ht, 1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string(arg1);
          if (GLOBAL(php3_HeaderPrinted) == 1) {
  #if DEBUG
                  php3_error(E_WARNING, "Cannot add more header information - the header was already sent "
--- 105,112 ----
***************
*** 115,124 ****
           * Not entirely sure this is the right way to support the header
           * command in the Apache module. Comments?
           */
! r = strchr(arg1->value.str.val, ':');
          if (r) {
                  *r = '\0';
! if (!strcasecmp(arg1->value.str.val, "Content-type")) {
                          if (*(r + 1) == ' ')
                                  GLOBAL(php3_rqst)->content_type = pstrdup(GLOBAL(php3_rqst)->pool,r + 2);
                          else
--- 120,129 ----
           * Not entirely sure this is the right way to support the header
           * command in the Apache module. Comments?
           */
! r = strchr(headerline, ':');
          if (r) {
                  *r = '\0';
! if (!strcasecmp(headerline, "Content-type")) {
                          if (*(r + 1) == ' ')
                                  GLOBAL(php3_rqst)->content_type = pstrdup(GLOBAL(php3_rqst)->pool,r + 2);
                          else
***************
*** 129,135 ****
                                  rr = r + 2;
                          else
                                  rr = r + 1;
! if (php3_ini.safe_mode && (!strcasecmp(arg1->value.str.val, "WWW-authenticate"))) {
                                  myuid = _php3_getuid();
                                  sprintf(temp2, "realm=\"%ld ", myuid); /* SAFE */
                                  temp = _php3_regreplace("realm=\"", temp2, rr, 1, 0);
--- 134,140 ----
                                  rr = r + 2;
                          else
                                  rr = r + 1;
! if (php3_ini.safe_mode && (!strcasecmp(headerline, "WWW-authenticate"))) {
                                  myuid = _php3_getuid();
                                  sprintf(temp2, "realm=\"%ld ", myuid); /* SAFE */
                                  temp = _php3_regreplace("realm=\"", temp2, rr, 1, 0);
***************
*** 141,178 ****
                                                  temp = _php3_regreplace("$", temp2, rr, 0, 0);
                                          }
                                  }
! table_set(GLOBAL(php3_rqst)->headers_out, arg1->value.str.val, temp);
                          } else
! table_set(GLOBAL(php3_rqst)->headers_out, arg1->value.str.val, rr);
                  }
! if (!strcasecmp(arg1->value.str.val, "location")) {
                          GLOBAL(php3_rqst)->status = REDIRECT;
                  }
                  *r = ':';
                  GLOBAL(php3_HeaderPrinted) = 2;
          }
! if (!strncasecmp(arg1->value.str.val, "http/", 5)) {
! if (strlen(arg1->value.str.val) > 9) {
! GLOBAL(php3_rqst)->status = atoi(&((arg1->value.str.val)[9]));
                  }
                  /* Use a pstrdup here to get the memory straight from Apache's per-request pool to
                   * avoid having our own memory manager complain about this memory not being freed
                   * because it really shouldn't be freed until the end of the request and it isn't
                   * easy for us to figure out when we allocated it vs. when something else might have.
                   */
! GLOBAL(php3_rqst)->status_line = pstrdup(GLOBAL(php3_rqst)->pool,&((arg1->value.str.val)[9]));
          }
  #else
! r = strchr(arg1->value.str.val, ':');
          if (r) {
                  *r = '\0';
! if (!strcasecmp(arg1->value.str.val, "Content-type")) {
                          if (GLOBAL(cont_type)) efree(GLOBAL(cont_type));
                          GLOBAL(cont_type) = estrdup(r + 1);
  #if 0 /*WIN32|WINNT / *M$ does us again*/
                          if (!strcmp(GLOBAL(cont_type)," text/html")){
                                  *r=':';
! PUTS(arg1->value.str.val);
                                  PUTS("\015\012");
                          }
  #endif
--- 146,183 ----
                                                  temp = _php3_regreplace("$", temp2, rr, 0, 0);
                                          }
                                  }
! table_set(GLOBAL(php3_rqst)->headers_out, headerline, temp);
                          } else
! table_set(GLOBAL(php3_rqst)->headers_out, headerline, rr);
                  }
! if (!strcasecmp(headerline, "location")) {
                          GLOBAL(php3_rqst)->status = REDIRECT;
                  }
                  *r = ':';
                  GLOBAL(php3_HeaderPrinted) = 2;
          }
! if (!strncasecmp(headerline, "http/", 5)) {
! if (strlen(headerline) > 9) {
! GLOBAL(php3_rqst)->status = atoi(&(headerline[9]));
                  }
                  /* Use a pstrdup here to get the memory straight from Apache's per-request pool to
                   * avoid having our own memory manager complain about this memory not being freed
                   * because it really shouldn't be freed until the end of the request and it isn't
                   * easy for us to figure out when we allocated it vs. when something else might have.
                   */
! GLOBAL(php3_rqst)->status_line = pstrdup(GLOBAL(php3_rqst)->pool,&(headerline[9]));
          }
  #else
! r = strchr(headerline, ':');
          if (r) {
                  *r = '\0';
! if (!strcasecmp(headerline, "Content-type")) {
                          if (GLOBAL(cont_type)) efree(GLOBAL(cont_type));
                          GLOBAL(cont_type) = estrdup(r + 1);
  #if 0 /*WIN32|WINNT / *M$ does us again*/
                          if (!strcmp(GLOBAL(cont_type)," text/html")){
                                  *r=':';
! PUTS(headerline);
                                  PUTS("\015\012");
                          }
  #endif
***************
*** 180,186 ****
                          *r = ':';
  #if USE_SAPI
                          {
! char *tempstr=emalloc(strlen(arg1->value.str.val)+2);
                                  
                                  sprintf(tempstr,"%s\015\012",tempstr);
                                  GLOBAL(sapi_rqst)->header(GLOBAL(sapi_rqst)->scid,tempstr);
--- 185,191 ----
                          *r = ':';
  #if USE_SAPI
                          {
! char *tempstr=emalloc(strlen(headerline)+2);
                                  
                                  sprintf(tempstr,"%s\015\012",tempstr);
                                  GLOBAL(sapi_rqst)->header(GLOBAL(sapi_rqst)->scid,tempstr);
***************
*** 188,197 ****
                          }
  #else /* CGI BINARY or FHTTPD */
  #if FHTTPD
! php3_fhttpd_puts_header(arg1->value.str.val);
              php3_fhttpd_puts_header("\r\n");
  #else
! PUTS(arg1->value.str.val);
                          PUTS("\015\012");
  #endif
  #endif/* end if SAPI */
--- 193,202 ----
                          }
  #else /* CGI BINARY or FHTTPD */
  #if FHTTPD
! php3_fhttpd_puts_header(headerline);
              php3_fhttpd_puts_header("\r\n");
  #else
! PUTS(headerline);
                          PUTS("\015\012");
  #endif
  #endif/* end if SAPI */
***************
*** 199,215 ****
          } else {
  #if USE_SAPI
                  {
! char *tempstr=emalloc(strlen(arg1->value.str.val)+2);
                  sprintf(tempstr,"%s\015\012",tempstr);
                  GLOBAL(sapi_rqst)->header(GLOBAL(sapi_rqst)->scid,tempstr);
                  efree(tempstr);
                  }
  #else /* CGI BINARY or FHTTPD */
  #if FHTTPD
! php3_fhttpd_puts_header(arg1->value.str.val);
          php3_fhttpd_puts_header("\r\n");
  #else
! PUTS(arg1->value.str.val);
                  PUTS("\015\012");
  #endif
  #endif /* endif SAPI */
--- 204,220 ----
          } else {
  #if USE_SAPI
                  {
! char *tempstr=emalloc(strlen(headerline)+2);
                  sprintf(tempstr,"%s\015\012",tempstr);
                  GLOBAL(sapi_rqst)->header(GLOBAL(sapi_rqst)->scid,tempstr);
                  efree(tempstr);
                  }
  #else /* CGI BINARY or FHTTPD */
  #if FHTTPD
! php3_fhttpd_puts_header(headerline);
          php3_fhttpd_puts_header("\r\n");
  #else
! PUTS(headerline);
                  PUTS("\015\012");
  #endif
  #endif /* endif SAPI */
Index: php3/functions/head.h
diff -c php3/functions/head.h:1.20 php3/functions/head.h:1.21
*** php3/functions/head.h:1.20 Fri May 15 06:57:25 1998
--- php3/functions/head.h Sun Oct 25 16:34:53 1998
***************
*** 57,62 ****
--- 57,63 ----
  extern void php3_SetCookie(INTERNAL_FUNCTION_PARAMETERS);
  
  extern void php3_noheader(void);
+ extern PHPAPI void php3_addheaderline(char *headerline);
  extern PHPAPI int php3_header(void);
  extern void php3_noheader(void);
  extern int php3_headers_unsent(void);

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>