[PHP-DEV] CVS update: php3/functions From: shane (php-dev <email protected>)
Date: 08/30/98

Date: Sunday August 30, 1998 @ 15:26
Author: shane

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

Modified Files:
        zlib.c
Log Message:
Backport ziplib changes from 3.1 tree.

Index: php3/functions/zlib.c
diff -c php3/functions/zlib.c:1.7 php3/functions/zlib.c:1.8
*** php3/functions/zlib.c:1.7 Fri Aug 14 19:47:16 1998
--- php3/functions/zlib.c Sun Aug 30 15:26:35 1998
***************
*** 22,28 ****
     | Stefan Röhrich <sr <email protected>> |
     +----------------------------------------------------------------------+
   */
! /* $Id: zlib.c,v 1.7 1998/08/14 23:47:16 steffann Exp $ */
  
  #ifdef THREAD_SAFE
  #include "tls.h"
--- 22,32 ----
     | Stefan Röhrich <sr <email protected>> |
     +----------------------------------------------------------------------+
   */
! /* $Id: zlib.c,v 1.8 1998/08/30 19:26:35 shane Exp $ */
! #if !PHP_31 && defined(THREAD_SAFE)
! #undef THREAD_SAFE
! #endif
! #define IS_EXT_MODULE
  
  #ifdef THREAD_SAFE
  #include "tls.h"
***************
*** 35,45 ****
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <fcntl.h>
! #if MSVC5
  #include <windows.h>
  #include <winsock.h>
  #define O_RDONLY _O_RDONLY
  #include "win32/param.h"
  #else
  #include <sys/param.h>
  /* #include <sys/uio.h> */
--- 39,53 ----
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <fcntl.h>
! #if (WIN32|WINNT)
  #include <windows.h>
  #include <winsock.h>
  #define O_RDONLY _O_RDONLY
+ #if PHP_31
+ #include "os/nt/param.h"
+ #else
  #include "win32/param.h"
+ #endif
  #else
  #include <sys/param.h>
  /* #include <sys/uio.h> */
***************
*** 48,61 ****
  #include "internal_functions.h"
  #include "safe_mode.h"
  #include "php3_list.h"
  #include "php3_string.h"
  #include "php3_zlib.h"
  #include "fopen-wrappers.h"
  #if HAVE_PWD_H
  #if WIN32|WINNT
- #ifdef HAVE_UNISTD_H
- #undef HAVE_UNISTD_H
- #endif
  #include "win32/pwd.h"
  #else
  #include <pwd.h>
--- 56,70 ----
  #include "internal_functions.h"
  #include "safe_mode.h"
  #include "php3_list.h"
+ #if PHP_31
+ #include "ext/standard/php3_string.h"
+ #else
  #include "php3_string.h"
+ #endif
  #include "php3_zlib.h"
  #include "fopen-wrappers.h"
  #if HAVE_PWD_H
  #if WIN32|WINNT
  #include "win32/pwd.h"
  #else
  #include <pwd.h>
***************
*** 63,72 ****
--- 72,89 ----
  #endif
  #include "snprintf.h"
  #if HAVE_ZLIB
+ #if defined(HAVE_UNISTD_H) && (WIN32|WINNT)
+ #undef HAVE_UNISTD_H
+ #endif
+
  #include <zlib.h>
  
  #if COMPILE_DL
+ #if PHP_31
+ #include "ext/phpdl.h"
+ #else
  #include "dl/phpdl.h"
+ #endif
  #ifndef PUTS
  #define PUTS(a) php3_printf("%s",a)
  #endif
***************
*** 78,106 ****
  #endif
  #endif
  
- #if defined(THREAD_SAFE)
- DWORD ZLIBtls;
- static int numthreads=0;
- void *zlib_mutex;
  
  typedef struct zlib_global_struct{
          int gzgetss_state;
          int le_zp;
  }zlib_global_struct;
  
  #define ZLIB_GLOBAL(a) zlib_globals->a
  
! #define ZLIB_TLS_VARS \
! zlib_global_struct *zlib_globals; \
! zlib_globals=TlsGetValue(ZLIBtls);
  
  #else
- static int gzgetss_state = 0;
- int le_zp;
  #define ZLIB_GLOBAL(a) a
  #define ZLIB_TLS_VARS
  #endif
  
  function_entry php3_zlib_functions[] = {
          {"readgzfile", php3_readgzfile, NULL},
          {"gzrewind", php3_gzrewind, NULL},
--- 95,137 ----
  #endif
  #endif
  
  
+
+ #if defined(THREAD_SAFE)
  typedef struct zlib_global_struct{
+ #endif
          int gzgetss_state;
          int le_zp;
+ #if PHP_31
+ int magic_quotes_runtime;
+ int safe_mode;
+ char *include_path;
+ char *doc_root;
+ #endif
+ #if defined(THREAD_SAFE)
  }zlib_global_struct;
+ #endif
  
+ #if defined(THREAD_SAFE)
+ DWORD ZLIBtls;
+ static int numthreads=0;
+ void *zlib_mutex;
+
  #define ZLIB_GLOBAL(a) zlib_globals->a
  
! #define ZLIB_TLS_VARS zlib_global_struct *PHP3_TLS_GET(ZLIBtls,zlib_globals);
  
  #else
  #define ZLIB_GLOBAL(a) a
  #define ZLIB_TLS_VARS
  #endif
  
+ #if PHP_31
+ # define ZLIB_INI(a) ZLIB_GLOBAL(a)
+ #else
+ # define ZLIB_INI(a) php3_ini.a
+ #endif
+
  function_entry php3_zlib_functions[] = {
          {"readgzfile", php3_readgzfile, NULL},
          {"gzrewind", php3_gzrewind, NULL},
***************
*** 126,184 ****
  
  #if defined(COMPILE_DL)
  DLEXPORT php3_module_entry *get_module(void) { return &php3_zlib_module_entry; }
-
- #if (WIN32|WINNT) && defined(THREAD_SAFE)
-
- /*NOTE: You should have an odbc.def file where you
- export DllMain*/
- BOOL WINAPI DllMain(HANDLE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved)
- {
- return 1;
- }
  #endif
- #endif
  
  int php3_minit_zlib(INIT_FUNC_ARGS)
  {
! #if defined(THREAD_SAFE)
          zlib_global_struct *zlib_globals;
! #if !defined(COMPILE_DL)
! CREATE_MUTEX(zlib_mutex,"ZLib_TLS");
! SET_MUTEX(zlib_mutex);
          numthreads++;
          if (numthreads==1){
! if ((ZLIBtls=TlsAlloc())==0xFFFFFFFF){
! FREE_MUTEX(zlib_mutex);
! return 0;
! }}
! FREE_MUTEX(zlib_mutex);
! #endif
! zlib_globals = (zlib_global_struct *) LocalAlloc(LPTR, sizeof(zlib_global_struct));
! TlsSetValue(ZLIBtls, (void *) zlib_globals);
! #endif
!
          ZLIB_GLOBAL(le_zp) = register_list_destructors(gzclose,NULL);
          return SUCCESS;
  }
  
  int php3_mshutdown_zlib(void){
  #if defined(THREAD_SAFE)
! zlib_global_struct *zlib_globals;
! zlib_globals = TlsGetValue(ZLIBtls);
! if (zlib_globals != 0)
! LocalFree((HLOCAL) zlib_globals);
! #if !defined(COMPILE_DL)
! SET_MUTEX(zlib_mutex);
          numthreads--;
! if (!numthreads){
! if (!TlsFree(ZLIBtls)){
! FREE_MUTEX(zlib_mutex);
! return 0;
! }}
! FREE_MUTEX(zlib_mutex);
! #endif
  #endif
          return SUCCESS;
  }
--- 157,207 ----
  
  #if defined(COMPILE_DL)
  DLEXPORT php3_module_entry *get_module(void) { return &php3_zlib_module_entry; }
  #endif
  
  int php3_minit_zlib(INIT_FUNC_ARGS)
  {
! #ifdef THREAD_SAFE
          zlib_global_struct *zlib_globals;
! PHP3_MUTEX_ALLOC(zlib_mutex);
! PHP3_MUTEX_LOCK(zlib_mutex);
          numthreads++;
          if (numthreads==1){
! if (!PHP3_TLS_PROC_STARTUP(ZLIBtls)){
! PHP3_MUTEX_UNLOCK(zlib_mutex);
! PHP3_MUTEX_FREE(zlib_mutex);
! return FAILURE;
! }
! }
! PHP3_MUTEX_UNLOCK(zlib_mutex);
! if(!PHP3_TLS_THREAD_INIT(ZLIBtls,zlib_globals,zlib_global_struct)){
! PHP3_MUTEX_FREE(zlib_mutex);
! return FAILURE;
! }
! #endif
! /* get our ini variables here */
! cfg_get_long("safe_mode",&ZLIB_INI(safe_mode));
! cfg_get_long("magic_quotes_runtime",&ZLIB_INI(magic_quotes_runtime));
! cfg_get_string("doc_root",&ZLIB_INI(doc_root));
! cfg_get_string("include_path",&ZLIB_INI(include_path));
!
          ZLIB_GLOBAL(le_zp) = register_list_destructors(gzclose,NULL);
          return SUCCESS;
  }
  
  int php3_mshutdown_zlib(void){
  #if defined(THREAD_SAFE)
! ZLIB_TLS_VARS;
! PHP3_TLS_THREAD_FREE(zlib_globals);
! PHP3_MUTEX_LOCK(zlib_mutex);
          numthreads--;
! if (numthreads<1){
! PHP3_TLS_PROC_SHUTDOWN(ZLIBtls);
! PHP3_MUTEX_UNLOCK(zlib_mutex);
! PHP3_MUTEX_FREE(zlib_mutex);
! return SUCCESS;
! }
! PHP3_MUTEX_UNLOCK(zlib_mutex);
  #endif
          return SUCCESS;
  }
***************
*** 188,194 ****
                  PUTS("Zlib support active (compiled with ");
                  PUTS(ZLIB_VERSION);
                  PUTS(", linked with ");
! PUTS(zlibVersion());
                  PUTS(").");
  }
  
--- 211,217 ----
                  PUTS("Zlib support active (compiled with ");
                  PUTS(ZLIB_VERSION);
                  PUTS(", linked with ");
! PUTS((char *)zlibVersion());
                  PUTS(").");
  }
  
***************
*** 196,206 ****
  
  static gzFile php3_gzopen_wrapper(char *path, char *mode, int options)
  {
! if (options & USE_PATH && php3_ini.include_path != NULL) {
! return php3_gzopen_with_path(path, mode, php3_ini.include_path, NULL);
          }
          else {
! if (options & ENFORCE_SAFE_MODE && php3_ini.safe_mode && (!_php3_checkuid(path,1))) {
                          php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner of file to be read.");
                          return NULL;
                  }
--- 219,230 ----
  
  static gzFile php3_gzopen_wrapper(char *path, char *mode, int options)
  {
! ZLIB_TLS_VARS;
! if (options & USE_PATH && ZLIB_INI(include_path) != NULL) {
! return php3_gzopen_with_path(path, mode, ZLIB_INI(include_path), NULL);
          }
          else {
! if (options & ENFORCE_SAFE_MODE && ZLIB_INI(safe_mode) && (!_php3_checkuid(path,1))) {
                          php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner of file to be read.");
                          return NULL;
                  }
***************
*** 219,224 ****
--- 243,249 ----
          char trypath[MAXPATHLEN + 1];
          struct stat sb;
          gzFile *zp;
+ ZLIB_TLS_VARS;
          
          if (opened_path) {
                  *opened_path = NULL;
***************
*** 226,232 ****
          
          /* Relative path open */
          if (*filename == '.') {
! if (php3_ini.safe_mode &&(!_php3_checkuid(filename,2))) {
                          php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                          return(NULL);
                  }
--- 251,257 ----
          
          /* Relative path open */
          if (*filename == '.') {
! if (ZLIB_INI(safe_mode) &&(!_php3_checkuid(filename,2))) {
                          php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                          return(NULL);
                  }
***************
*** 244,251 ****
  #else
          if (*filename == '/') {
  #endif
! if (php3_ini.safe_mode) {
! snprintf(trypath,MAXPATHLEN,"%s%s",php3_ini.doc_root,filename);
                          if (!_php3_checkuid(trypath,2)) {
                                  php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                                  return(NULL);
--- 269,276 ----
  #else
          if (*filename == '/') {
  #endif
! if (ZLIB_INI(safe_mode)) {
! snprintf(trypath,MAXPATHLEN,"%s%s",ZLIB_INI(doc_root),filename);
                          if (!_php3_checkuid(trypath,2)) {
                                  php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                                  return(NULL);
***************
*** 263,269 ****
          }
  
          if (!path || (path && !*path)) {
! if (php3_ini.safe_mode &&(!_php3_checkuid(filename,2))) {
                          php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                          return(NULL);
                  }
--- 288,294 ----
          }
  
          if (!path || (path && !*path)) {
! if (ZLIB_INI(safe_mode) &&(!_php3_checkuid(filename,2))) {
                          php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                          return(NULL);
                  }
***************
*** 290,296 ****
                          end++;
                  }
                  snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
! if (php3_ini.safe_mode) {
                          if (stat(trypath,&sb) == 0 &&(!_php3_checkuid(trypath,2))) {
                                  php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                                  efree(pathbuf);
--- 315,321 ----
                          end++;
                  }
                  snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
! if (ZLIB_INI(safe_mode)) {
                          if (stat(trypath,&sb) == 0 &&(!_php3_checkuid(trypath,2))) {
                                  php3_error(E_WARNING,"SAFE MODE Restriction in effect. Invalid owner.");
                                  efree(pathbuf);
***************
*** 300,307 ****
                  if ((zp = gzopen(trypath, mode)) != NULL) {
                          if (_php3_check_open_basedir(trypath)) {
                                  gzclose(zp);
! efree(pathbuf);
! return NULL;
                          }
                          if (opened_path) {
                                  *opened_path = expand_filepath(trypath);
--- 325,332 ----
                  if ((zp = gzopen(trypath, mode)) != NULL) {
                          if (_php3_check_open_basedir(trypath)) {
                                  gzclose(zp);
! efree(pathbuf);
! return NULL;
                          }
                          if (opened_path) {
                                  *opened_path = expand_filepath(trypath);
***************
*** 321,326 ****
--- 346,352 ----
          char *slashed, buf[8192];
          register int i=0;
          int use_include_path = 0;
+ ZLIB_TLS_VARS;
  
          /* check args */
          switch (ARG_COUNT(ht)) {
***************
*** 355,361 ****
          /* Now loop through the file and do the magic quotes thing if needed */
          memset(buf,0,8191);
          while((int)gzgets(zp, buf, 8191)) {
! if (php3_ini.magic_quotes_runtime) {
                          int len;
                          
                          slashed = _php3_addslashes(buf,0,&len,0); /* 0 = don't free source string */
--- 381,387 ----
          /* Now loop through the file and do the magic quotes thing if needed */
          memset(buf,0,8191);
          while((int)gzgets(zp, buf, 8191)) {
! if (ZLIB_INI(magic_quotes_runtime)) {
                          int len;
                          
                          slashed = _php3_addslashes(buf,0,&len,0); /* 0 = don't free source string */
***************
*** 487,493 ****
                  efree(buf);
                  RETVAL_FALSE;
          } else {
! if (php3_ini.magic_quotes_runtime) {
                          return_value->value.str.val = _php3_addslashes(buf,0,&return_value->value.str.len,1);
                  } else {
                          return_value->value.str.val = buf;
--- 513,519 ----
                  efree(buf);
                  RETVAL_FALSE;
          } else {
! if (ZLIB_INI(magic_quotes_runtime)) {
                          return_value->value.str.val = _php3_addslashes(buf,0,&return_value->value.str.len,1);
                  } else {
                          return_value->value.str.val = buf;
***************
*** 682,688 ****
          }
  
          /* strip slashes only if the length wasn't specified explicitly */
! if (!arg3 && php3_ini.magic_quotes_runtime) {
                  _php3_stripslashes(arg2->value.str.val,&num_bytes);
          }
  
--- 708,714 ----
          }
  
          /* strip slashes only if the length wasn't specified explicitly */
! if (!arg3 && ZLIB_INI(magic_quotes_runtime)) {
                  _php3_stripslashes(arg2->value.str.val,&num_bytes);
          }
  
***************
*** 862,868 ****
          return_value->value.str.len = gzread(zp, return_value->value.str.val, len);
          return_value->value.str.val[return_value->value.str.len] = 0;
  
! if (php3_ini.magic_quotes_runtime) {
                  return_value->value.str.val = _php3_addslashes(return_value->value.str.val,return_value->value.str.len,&return_value->value.str.len,1);
          }
          return_value->type = IS_STRING;
--- 888,894 ----
          return_value->value.str.len = gzread(zp, return_value->value.str.val, len);
          return_value->value.str.val[return_value->value.str.len] = 0;
  
! if (ZLIB_INI(magic_quotes_runtime)) {
                  return_value->value.str.val = _php3_addslashes(return_value->value.str.val,return_value->value.str.len,&return_value->value.str.len,1);
          }
          return_value->type = IS_STRING;

--
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>