1999-04-22 02:48:28 +00:00
|
|
|
|
/*
|
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 13:13:16 +00:00
|
|
|
|
| PHP version 4.0 |
|
1999-04-22 02:48:28 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 01:32:05 +00:00
|
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-04-22 02:48:28 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 15:34:45 +00:00
|
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 15:34:45 +00:00
|
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 13:13:16 +00:00
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-22 02:48:28 +00:00
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
|
|
|
|
| Stefan R<EFBFBD>hrich <sr@linux.de> |
|
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
#define IS_EXT_MODULE
|
|
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <fcntl.h>
|
2000-02-11 15:59:30 +00:00
|
|
|
|
#ifdef PHP_WIN32
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include <winsock.h>
|
|
|
|
|
#define O_RDONLY _O_RDONLY
|
|
|
|
|
#include "win32/param.h"
|
|
|
|
|
#else
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
/* #include <sys/uio.h> */
|
|
|
|
|
#endif
|
|
|
|
|
#include "ext/standard/head.h"
|
|
|
|
|
#include "safe_mode.h"
|
1999-12-04 19:19:57 +00:00
|
|
|
|
#include "ext/standard/php_standard.h"
|
2000-04-05 21:43:03 +00:00
|
|
|
|
#include "ext/standard/info.h"
|
1999-12-04 19:19:57 +00:00
|
|
|
|
#include "php_zlib.h"
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#include "fopen-wrappers.h"
|
|
|
|
|
#if HAVE_PWD_H
|
2000-02-11 15:59:30 +00:00
|
|
|
|
#ifdef PHP_WIN32
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#include "win32/pwd.h"
|
|
|
|
|
#else
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
#if HAVE_ZLIB
|
2000-02-11 15:59:30 +00:00
|
|
|
|
#if defined(HAVE_UNISTD_H) && defined(PHP_WIN32)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#undef HAVE_UNISTD_H
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <zlib.h>
|
|
|
|
|
|
2000-05-23 09:33:51 +00:00
|
|
|
|
#ifdef COMPILE_DL_ZLIB
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#ifndef PUTS
|
1999-08-02 19:17:14 +00:00
|
|
|
|
#define PUTS(a) php_printf("%s",a)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef PUTC
|
|
|
|
|
#define PUTC(a) PUTS(a)
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef PHPWRITE
|
1999-12-17 19:16:50 +00:00
|
|
|
|
#define PHPWRITE(a,n) php_write((a),(n))
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-06 19:09:47 +00:00
|
|
|
|
#ifdef ZTS
|
|
|
|
|
int zlib_globals_id;
|
|
|
|
|
#else
|
|
|
|
|
static php_zlib_globals zlib_globals;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
1999-09-06 19:09:47 +00:00
|
|
|
|
/* True globals, no need for thread safety */
|
|
|
|
|
static int le_zp;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
1999-12-17 22:34:04 +00:00
|
|
|
|
function_entry php_zlib_functions[] = {
|
1999-08-02 21:12:16 +00:00
|
|
|
|
PHP_FE(readgzfile, NULL)
|
|
|
|
|
PHP_FE(gzrewind, NULL)
|
|
|
|
|
PHP_FE(gzclose, NULL)
|
|
|
|
|
PHP_FE(gzeof, NULL)
|
|
|
|
|
PHP_FE(gzgetc, NULL)
|
|
|
|
|
PHP_FE(gzgets, NULL)
|
|
|
|
|
PHP_FE(gzgetss, NULL)
|
|
|
|
|
PHP_FE(gzread, NULL)
|
|
|
|
|
PHP_FE(gzopen, NULL)
|
|
|
|
|
PHP_FE(gzpassthru, NULL)
|
|
|
|
|
PHP_FE(gzseek, NULL)
|
|
|
|
|
PHP_FE(gztell, NULL)
|
|
|
|
|
PHP_FE(gzwrite, NULL)
|
|
|
|
|
PHP_FALIAS(gzputs, gzwrite, NULL)
|
|
|
|
|
PHP_FE(gzfile, NULL)
|
2000-05-25 16:35:49 +00:00
|
|
|
|
PHP_FE(gzcompress, NULL)
|
|
|
|
|
PHP_FE(gzuncompress, NULL)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
1999-12-17 22:34:04 +00:00
|
|
|
|
zend_module_entry php_zlib_module_entry = {
|
1999-08-02 21:12:16 +00:00
|
|
|
|
"zlib",
|
1999-12-17 22:34:04 +00:00
|
|
|
|
php_zlib_functions,
|
1999-08-02 21:12:16 +00:00
|
|
|
|
PHP_MINIT(zlib),
|
|
|
|
|
PHP_MSHUTDOWN(zlib),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
PHP_MINFO(zlib),
|
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
1999-04-22 02:48:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2000-05-23 09:33:51 +00:00
|
|
|
|
#ifdef COMPILE_DL_ZLIB
|
2000-05-02 00:30:36 +00:00
|
|
|
|
ZEND_GET_MODULE(php_zlib)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-04 21:51:54 +00:00
|
|
|
|
static void phpi_destructor_gzclose(gzFile *zp) {
|
1999-08-02 21:12:16 +00:00
|
|
|
|
(void)gzclose(zp);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-06 19:09:47 +00:00
|
|
|
|
#ifdef ZTS
|
|
|
|
|
static void php_zlib_init_globals(ZLIBLS_D)
|
|
|
|
|
{
|
|
|
|
|
ZLIBG(gzgetss_state) = 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-08-02 21:12:16 +00:00
|
|
|
|
PHP_MINIT_FUNCTION(zlib)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
{
|
1999-09-06 19:09:47 +00:00
|
|
|
|
#ifdef ZTS
|
1999-12-12 11:02:24 +00:00
|
|
|
|
zlib_globals_id = ts_allocate_id(sizeof(php_zlib_globals), (ts_allocate_ctor) php_zlib_init_globals, NULL);
|
1999-09-06 19:09:47 +00:00
|
|
|
|
#else
|
|
|
|
|
ZLIBG(gzgetss_state)=0;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
#endif
|
1999-09-06 19:09:47 +00:00
|
|
|
|
le_zp = register_list_destructors(phpi_destructor_gzclose,NULL);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-02 21:12:16 +00:00
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(zlib)
|
|
|
|
|
{
|
1999-04-22 02:48:28 +00:00
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-02 21:12:16 +00:00
|
|
|
|
PHP_MINFO_FUNCTION(zlib)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
{
|
2000-04-05 21:43:03 +00:00
|
|
|
|
php_info_print_table_start();
|
|
|
|
|
php_info_print_table_row(2, "ZLib Support", "enabled");
|
|
|
|
|
php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION );
|
|
|
|
|
php_info_print_table_row(2, "Linked Version", (char *)zlibVersion() );
|
|
|
|
|
php_info_print_table_end();
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-17 22:34:04 +00:00
|
|
|
|
static gzFile php_gzopen_wrapper(char *path, char *mode, int options)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
{
|
2000-06-26 17:40:24 +00:00
|
|
|
|
FILE *f;
|
2000-07-06 11:25:24 +00:00
|
|
|
|
int issock=0, socketd=0;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-07-06 11:25:24 +00:00
|
|
|
|
f = php_fopen_wrapper(path, mode, options, &issock, &socketd, NULL);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-06-26 17:40:24 +00:00
|
|
|
|
if (!f) {
|
|
|
|
|
return NULL;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
2000-06-26 17:40:24 +00:00
|
|
|
|
return gzdopen(fileno(f), mode);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-18 19:03:35 +00:00
|
|
|
|
/* {{{ proto array gzfile(string filename [, int use_include_path])
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Read und uncompress entire .gz-file into an array */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzfile) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **filename, **arg2;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile zp;
|
|
|
|
|
char *slashed, buf[8192];
|
|
|
|
|
register int i=0;
|
|
|
|
|
int use_include_path = 0;
|
1999-09-06 19:09:47 +00:00
|
|
|
|
PLS_FETCH();
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
|
|
|
|
/* check args */
|
2000-06-05 19:47:54 +00:00
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
case 1:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(1,&filename) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(2,&filename,&arg2) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_long_ex(arg2);
|
2000-06-26 18:19:35 +00:00
|
|
|
|
use_include_path = (*arg2)->value.lval?USE_PATH:0;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_string_ex(filename);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
1999-12-17 22:34:04 +00:00
|
|
|
|
zp = php_gzopen_wrapper((*filename)->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
if (!zp) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
php_error(E_WARNING,"gzFile(\"%s\") - %s",(*filename)->value.str.val,strerror(errno));
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize return array */
|
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now loop through the file and do the magic quotes thing if needed */
|
|
|
|
|
memset(buf,0,8191);
|
1999-05-21 10:06:25 +00:00
|
|
|
|
while(gzgets(zp, buf, 8191) != NULL) {
|
1999-04-23 04:12:13 +00:00
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
int len;
|
|
|
|
|
|
1999-09-04 13:18:59 +00:00
|
|
|
|
slashed = php_addslashes(buf,0,&len,0); /* 0 = don't free source string */
|
1999-04-22 02:48:28 +00:00
|
|
|
|
add_index_stringl(return_value, i++, slashed, len, 0);
|
|
|
|
|
} else {
|
|
|
|
|
add_index_string(return_value, i++, buf, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gzclose(zp);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto int gzopen(string filename, string mode [, int use_include_path])
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Open a .gz-file and return a .gz-file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzopen) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1, **arg2, **arg3;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
|
|
|
|
char *p;
|
|
|
|
|
int use_include_path = 0;
|
1999-09-06 19:09:47 +00:00
|
|
|
|
ZLIBLS_FETCH();
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
switch(ZEND_NUM_ARGS()) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
case 2:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(2,&arg1,&arg2) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(3,&arg1,&arg2,&arg3) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_long_ex(arg3);
|
2000-06-26 18:19:35 +00:00
|
|
|
|
use_include_path = (*arg3)->value.lval?USE_PATH:0;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_string_ex(arg1);
|
|
|
|
|
convert_to_string_ex(arg2);
|
|
|
|
|
p = estrndup((*arg2)->value.str.val,(*arg2)->value.str.len);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We need a better way of returning error messages from
|
1999-12-17 22:34:04 +00:00
|
|
|
|
* php_gzopen_wrapper().
|
1999-04-22 02:48:28 +00:00
|
|
|
|
*/
|
1999-12-17 22:34:04 +00:00
|
|
|
|
zp = php_gzopen_wrapper((*arg1)->value.str.val, p, use_include_path|ENFORCE_SAFE_MODE);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
if (!zp) {
|
1999-08-02 19:17:14 +00:00
|
|
|
|
php_error(E_WARNING,"gzopen(\"%s\",\"%s\") - %s",
|
1999-09-25 11:23:02 +00:00
|
|
|
|
(*arg1)->value.str.val, p, strerror(errno));
|
1999-04-22 02:48:28 +00:00
|
|
|
|
efree(p);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
1999-09-06 19:09:47 +00:00
|
|
|
|
ZLIBG(gzgetss_state)=0;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
efree(p);
|
1999-09-06 19:09:47 +00:00
|
|
|
|
ZEND_REGISTER_RESOURCE(return_value, zp, le_zp);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto int gzclose(int zp)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Close an open .gz-file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzclose) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
|
|
|
|
zend_list_delete((*arg1)->value.lval);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto int gzeof(int zp)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Test for end-of-file on a .gz-file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzeof) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
if ((gzeof(zp))) {
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string gzgets(int zp, int length)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Get a line from .gz-file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzgets) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1, **arg2;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
1999-09-04 21:51:54 +00:00
|
|
|
|
int len;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
char *buf;
|
1999-09-06 19:09:47 +00:00
|
|
|
|
PLS_FETCH();
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
|
len = (*arg2)->value.lval;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
buf = emalloc(sizeof(char) * (len + 1));
|
|
|
|
|
/* needed because recv doesnt put a null at the end*/
|
|
|
|
|
memset(buf,0,len+1);
|
1999-05-21 10:06:25 +00:00
|
|
|
|
if (!(gzgets(zp, buf, len) != NULL)) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
efree(buf);
|
|
|
|
|
RETVAL_FALSE;
|
|
|
|
|
} else {
|
1999-04-23 04:12:13 +00:00
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
1999-09-04 13:18:59 +00:00
|
|
|
|
return_value->value.str.val = php_addslashes(buf,0,&return_value->value.str.len,1);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
return_value->value.str.val = buf;
|
|
|
|
|
return_value->value.str.len = strlen(return_value->value.str.val);
|
|
|
|
|
}
|
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string gzgetc(int zp)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Get a character from .gz-file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzgetc) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
1999-09-04 21:51:54 +00:00
|
|
|
|
int c;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
char *buf;
|
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
buf = emalloc(sizeof(char) * 2);
|
|
|
|
|
if ((c=gzgetc(zp)) == (-1)) {
|
|
|
|
|
efree(buf);
|
|
|
|
|
RETVAL_FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
buf[0]=(char)c;
|
|
|
|
|
buf[1]='\0';
|
|
|
|
|
return_value->value.str.val = buf;
|
|
|
|
|
return_value->value.str.len = 1;
|
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* Strip any HTML tags while reading */
|
1999-09-22 07:43:36 +00:00
|
|
|
|
/* {{{ proto string gzgetss(int zp, int length [, string allowable_tags])
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Get a line from file pointer and strip HTML tags */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzgetss)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
{
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **fd, **bytes, **allow=NULL;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
1999-09-07 19:05:37 +00:00
|
|
|
|
int len;
|
|
|
|
|
char *buf;
|
2000-02-08 21:29:18 +00:00
|
|
|
|
char *allowed_tags=NULL;
|
|
|
|
|
int allowed_tags_len=0;
|
1999-09-06 19:09:47 +00:00
|
|
|
|
ZLIBLS_FETCH();
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
switch(ZEND_NUM_ARGS()) {
|
1999-09-21 00:15:21 +00:00
|
|
|
|
case 2:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if(zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) {
|
1999-09-21 00:15:21 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if(zend_get_parameters_ex(3, &fd, &bytes, &allow) == FAILURE) {
|
1999-09-21 00:15:21 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_string_ex(allow);
|
2000-02-08 21:29:18 +00:00
|
|
|
|
allowed_tags = (*allow)->value.str.val;
|
|
|
|
|
allowed_tags_len = (*allow)->value.str.len;
|
1999-09-21 00:15:21 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
break;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_long_ex(bytes);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
len = (*bytes)->value.lval;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, fd, -1, "Zlib file", le_zp);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
|
|
|
|
buf = emalloc(sizeof(char) * (len + 1));
|
|
|
|
|
/*needed because recv doesnt set null char at end*/
|
|
|
|
|
memset(buf,0,len+1);
|
1999-05-21 10:06:25 +00:00
|
|
|
|
if (!(gzgets(zp, buf, len) != NULL)) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
efree(buf);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-21 17:50:51 +00:00
|
|
|
|
/* strlen() can be used here since we are doing it on the return of an fgets() anyway */
|
2000-02-08 21:29:18 +00:00
|
|
|
|
php_strip_tags(buf, strlen(buf), ZLIBG(gzgetss_state), allowed_tags, allowed_tags_len);
|
1999-09-07 19:05:37 +00:00
|
|
|
|
RETURN_STRING(buf, 0);
|
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto int gzwrite(int zp, string str [, int length])
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Binary-safe .gz-file write */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzwrite) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1, **arg2, **arg3=NULL;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
1999-09-04 21:51:54 +00:00
|
|
|
|
int ret;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
int num_bytes;
|
1999-09-06 19:09:47 +00:00
|
|
|
|
PLS_FETCH();
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
case 2:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_string_ex(arg2);
|
|
|
|
|
num_bytes = (*arg2)->value.str.len;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3)==FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_string_ex(arg2);
|
|
|
|
|
convert_to_long_ex(arg3);
|
|
|
|
|
num_bytes = MIN((*arg3)->value.lval, (*arg2)->value.str.len);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
|
|
|
|
/* strip slashes only if the length wasn't specified explicitly */
|
1999-04-23 04:12:13 +00:00
|
|
|
|
if (!arg3 && PG(magic_quotes_runtime)) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
php_stripslashes((*arg2)->value.str.val,&num_bytes);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ret = gzwrite(zp, (*arg2)->value.str.val,num_bytes);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
1999-08-09 20:18:00 +00:00
|
|
|
|
/* {{{ proto int gzputs(int zp, string str [, int length])
|
|
|
|
|
An alias for gzwrite */
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
/* {{{ proto int gzrewind(int zp)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Rewind the position of a .gz-file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzrewind) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzrewind(zp);
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto int gztell(int zp)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Get .gz-file pointer's read/write position */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gztell) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
long pos;
|
|
|
|
|
gzFile *zp;
|
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
pos = gztell(zp);
|
|
|
|
|
RETURN_LONG(pos);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto int gzseek(int zp, int offset)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Seek on a file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzseek) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1, **arg2;
|
1999-09-04 21:51:54 +00:00
|
|
|
|
int ret;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_long_ex(arg2);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ret = gzseek(zp, (*arg2)->value.lval, SEEK_SET);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Read a file and write the ouput to stdout
|
|
|
|
|
*/
|
|
|
|
|
/* {{{ proto int readgzfile(string filename [, int use_include_path])
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Output a .gz-file */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(readgzfile) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1, **arg2;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
char buf[8192];
|
|
|
|
|
gzFile *zp;
|
|
|
|
|
int b, size;
|
|
|
|
|
int use_include_path = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* check args */
|
2000-06-05 19:47:54 +00:00
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
case 1:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(1,&arg1) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
1999-12-18 22:40:35 +00:00
|
|
|
|
if (zend_get_parameters_ex(2,&arg1,&arg2) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_long_ex(arg2);
|
2000-06-26 18:19:35 +00:00
|
|
|
|
use_include_path = (*arg2)->value.lval?USE_PATH:0;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_string_ex(arg1);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We need a better way of returning error messages from
|
1999-12-17 22:34:04 +00:00
|
|
|
|
* php_gzopen_wrapper().
|
1999-04-22 02:48:28 +00:00
|
|
|
|
*/
|
1999-12-17 22:34:04 +00:00
|
|
|
|
zp = php_gzopen_wrapper((*arg1)->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
if (!zp){
|
1999-09-25 11:23:02 +00:00
|
|
|
|
php_error(E_WARNING,"ReadGzFile(\"%s\") - %s",(*arg1)->value.str.val,strerror(errno));
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
size= 0;
|
|
|
|
|
while((b = gzread(zp, buf, sizeof(buf))) > 0) {
|
|
|
|
|
PHPWRITE(buf,b);
|
|
|
|
|
size += b ;
|
|
|
|
|
}
|
|
|
|
|
gzclose(zp);
|
|
|
|
|
RETURN_LONG(size);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Read to EOF on a file descriptor and write the output to stdout.
|
|
|
|
|
*/
|
|
|
|
|
/* {{{ proto int gzpassthru(int zp)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Output all remaining data from a .gz-file pointer */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzpassthru) {
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
|
|
|
|
char buf[8192];
|
1999-09-04 21:51:54 +00:00
|
|
|
|
int size, b;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
size = 0;
|
|
|
|
|
while((b = gzread(zp, buf, sizeof(buf))) > 0) {
|
|
|
|
|
PHPWRITE(buf,b);
|
|
|
|
|
size += b ;
|
|
|
|
|
}
|
|
|
|
|
/* gzclose(zp); */
|
1999-09-25 11:23:02 +00:00
|
|
|
|
zend_list_delete((*arg1)->value.lval);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
RETURN_LONG(size);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
1999-09-06 08:59:48 +00:00
|
|
|
|
/* {{{ proto string gzread(int zp, int length)
|
2000-02-24 14:43:53 +00:00
|
|
|
|
Binary-safe file read */
|
1999-05-21 10:06:25 +00:00
|
|
|
|
PHP_FUNCTION(gzread)
|
1999-04-22 02:48:28 +00:00
|
|
|
|
{
|
1999-09-25 11:23:02 +00:00
|
|
|
|
pval **arg1, **arg2;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
gzFile *zp;
|
1999-09-04 21:51:54 +00:00
|
|
|
|
int len;
|
1999-09-06 19:09:47 +00:00
|
|
|
|
PLS_FETCH();
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-22 02:48:28 +00:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-25 11:23:02 +00:00
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
|
len = (*arg2)->value.lval;
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
1999-09-25 11:23:02 +00:00
|
|
|
|
ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp);
|
1999-09-04 21:51:54 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
return_value->value.str.val = emalloc(sizeof(char) * (len + 1));
|
|
|
|
|
/* needed because recv doesnt put a null at the end*/
|
|
|
|
|
|
|
|
|
|
return_value->value.str.len = gzread(zp, return_value->value.str.val, len);
|
|
|
|
|
return_value->value.str.val[return_value->value.str.len] = 0;
|
|
|
|
|
|
1999-04-23 04:12:13 +00:00
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
1999-09-04 13:18:59 +00:00
|
|
|
|
return_value->value.str.val = php_addslashes(return_value->value.str.val,return_value->value.str.len,&return_value->value.str.len,1);
|
1999-04-22 02:48:28 +00:00
|
|
|
|
}
|
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
|
}
|
2000-05-25 16:35:49 +00:00
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
/* }}} */
|
2000-05-25 16:35:49 +00:00
|
|
|
|
|
|
|
|
|
|
2000-07-13 18:21:40 +00:00
|
|
|
|
/* {{{ proto string gzcompress(string data [, int level])
|
|
|
|
|
Gzip-compress a string */
|
2000-05-25 16:35:49 +00:00
|
|
|
|
PHP_FUNCTION(gzcompress)
|
|
|
|
|
{
|
|
|
|
|
zval **data, **zlimit = NULL;
|
|
|
|
|
int limit,status;
|
|
|
|
|
unsigned long l2;
|
|
|
|
|
char *s2;
|
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
2000-05-25 16:35:49 +00:00
|
|
|
|
case 1:
|
|
|
|
|
if (zend_get_parameters_ex(1, &data) == FAILURE)
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
limit=-1;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (zend_get_parameters_ex(2, &data, &zlimit) == FAILURE)
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
convert_to_long_ex(zlimit);
|
|
|
|
|
limit = (*zlimit)->value.lval;
|
|
|
|
|
if((limit<0)||(limit>9)) {
|
|
|
|
|
php_error(E_WARNING,"gzcompress: compression level must be whithin 0..9");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
convert_to_string_ex(data);
|
|
|
|
|
|
|
|
|
|
l2 = (*data)->value.str.len + ((*data)->value.str.len/1000) + 15;
|
|
|
|
|
s2 = (char *) emalloc(l2);
|
|
|
|
|
if(! s2) RETURN_FALSE;
|
|
|
|
|
|
|
|
|
|
if(limit>=0) {
|
|
|
|
|
status = compress2(s2,&l2,(*data)->value.str.val, (*data)->value.str.len,limit);
|
|
|
|
|
} else {
|
|
|
|
|
status = compress(s2,&l2,(*data)->value.str.val, (*data)->value.str.len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(status==Z_OK) {
|
|
|
|
|
RETURN_STRINGL(s2, l2, 0);
|
|
|
|
|
} else {
|
|
|
|
|
efree(s2);
|
|
|
|
|
php_error(E_WARNING,"gzcompress: %s",zError(status));
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2000-07-13 18:27:10 +00:00
|
|
|
|
/* {{{ proto string gzuncompress(string data, int length)
|
2000-07-13 18:21:40 +00:00
|
|
|
|
Unzip a gzip-compressed string */
|
2000-05-25 16:35:49 +00:00
|
|
|
|
PHP_FUNCTION(gzuncompress)
|
|
|
|
|
{
|
|
|
|
|
zval **data, **zlimit = NULL;
|
|
|
|
|
int status,factor=1,maxfactor=8;
|
|
|
|
|
unsigned long plength=0,length;
|
|
|
|
|
char *s1=NULL,*s2=NULL;
|
|
|
|
|
|
2000-06-05 19:47:54 +00:00
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
2000-05-25 16:35:49 +00:00
|
|
|
|
case 1:
|
|
|
|
|
if (zend_get_parameters_ex(1, &data) == FAILURE)
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
length=0;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (zend_get_parameters_ex(2, &data, &zlimit) == FAILURE)
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
convert_to_long_ex(zlimit);
|
|
|
|
|
if((*zlimit)->value.lval<=0) {
|
|
|
|
|
php_error(E_WARNING,"gzuncompress: length must be greater zero");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
plength = (*zlimit)->value.lval;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
convert_to_string_ex(data);
|
2000-06-16 18:24:02 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
zlib::uncompress() wants to know the output data length
|
|
|
|
|
if none was given as a parameter
|
|
|
|
|
we try from input length * 2 up to input length * 2^8
|
|
|
|
|
doubling it whenever it wasn't big enough
|
|
|
|
|
that should be eneugh for all real life cases
|
|
|
|
|
*/
|
2000-05-25 16:35:49 +00:00
|
|
|
|
do {
|
|
|
|
|
length=plength?plength:(*data)->value.str.len*(1<<factor++);
|
|
|
|
|
s2 = (char *) erealloc(s1,length);
|
|
|
|
|
if(! s2) { if(s1) efree(s1); RETURN_FALSE; }
|
|
|
|
|
status = uncompress(s2, &length ,(*data)->value.str.val, (*data)->value.str.len);
|
|
|
|
|
s1=s2;
|
|
|
|
|
} while((status==Z_BUF_ERROR)&&(!plength)&&(factor<maxfactor));
|
|
|
|
|
|
|
|
|
|
if(status==Z_OK) {
|
|
|
|
|
s2 = erealloc(s2, length);
|
|
|
|
|
RETURN_STRINGL(s2, length, 0);
|
|
|
|
|
} else {
|
|
|
|
|
efree(s2);
|
|
|
|
|
php_error(E_WARNING,"gzuncompress: %s",zError(status));
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
1999-04-22 02:48:28 +00:00
|
|
|
|
|
|
|
|
|
#endif /* HAVE_ZLIB */
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* tab-width: 4
|
1999-08-02 21:12:16 +00:00
|
|
|
|
* c-basic-offset: 4
|
1999-04-22 02:48:28 +00:00
|
|
|
|
* End:
|
|
|
|
|
*/
|