8 Commits
0.2.6 ... 0.3.0

Author SHA1 Message Date
michael
178e5c07c5 Fixed Segmentation Fault on use (Bug #21578)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@312414 c90b9560-bf6c-de11-be94-00142212c4b1
2011-06-23 20:43:19 +00:00
michael
9b925ac532 Fixed Bug #22566 (Can't set ini variable)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@312401 c90b9560-bf6c-de11-be94-00142212c4b1
2011-06-23 11:36:40 +00:00
michael
4411953272 Provide a default value for expect.match_max (Bug #21823)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@307741 c90b9560-bf6c-de11-be94-00142212c4b1
2011-01-25 21:07:27 +00:00
michael
f80a041dac Fixed bug #16836 (introduce expect.match_max .ini parameter for asterisk match buffer size)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@307293 c90b9560-bf6c-de11-be94-00142212c4b1
2011-01-09 08:10:44 +00:00
michael
ea50047133 Fixed package version
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@304244 c90b9560-bf6c-de11-be94-00142212c4b1
2010-10-10 07:43:20 +00:00
michael
e16b06dede Fixed bug #18998 (Change expect.logfile on runtime leave file descriptor opened)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@304243 c90b9560-bf6c-de11-be94-00142212c4b1
2010-10-10 07:37:35 +00:00
johannes
80e342cf6b s,function_entry,zend_function_entry,
As announced in http://news.php.net/php.pecl.dev/7123


git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@297236 c90b9560-bf6c-de11-be94-00142212c4b1
2010-03-31 20:39:48 +00:00
pajoye
3e030e95e6 - update to package.xml v2
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@290265 c90b9560-bf6c-de11-be94-00142212c4b1
2009-11-05 11:49:14 +00:00
4 changed files with 163 additions and 47 deletions

View File

@@ -33,7 +33,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_expect_expectl, 0, 0, 2)
ZEND_END_ARG_INFO()
/* {{{ expect_functions[] */
function_entry expect_functions[] = {
zend_function_entry expect_functions[] = {
PHP_FE(expect_popen, arginfo_expect_popen)
PHP_FE(expect_expectl, arginfo_expect_expectl)
{ NULL, NULL, NULL }
@@ -61,13 +61,47 @@ zend_module_entry expect_module_entry = {
ZEND_GET_MODULE(expect)
#endif
ZEND_DECLARE_MODULE_GLOBALS(expect)
/* {{{ php_expect_init_globals
*/
static void php_expect_init_globals (zend_expect_globals *globals TSRMLS_DC)
{
globals->logfile_stream = NULL;
}
/* }}} */
/* {{{ php_expect_destroy_globals
*/
static void php_expect_destroy_globals(zend_expect_globals *globals TSRMLS_DC)
{
if (globals->logfile_stream) {
php_stream_close(globals->logfile_stream);
}
}
/* }}} */
/* {{{ PHP_INI_MH
* */
static PHP_INI_MH(OnSetExpectTimeout)
{
if (new_value) {
exp_timeout = atoi(new_value);
return SUCCESS;
}
return FAILURE;
}
/* }}} */
/* {{{ PHP_INI_MH
* */
static PHP_INI_MH(OnSetExpectMatchMax)
{
if (new_value) {
exp_match_max = atoi(new_value);
return SUCCESS;
}
return FAILURE;
}
/* }}} */
@@ -82,7 +116,9 @@ static PHP_INI_MH(OnSetExpectLogUser)
} else {
exp_loguser = 1;
}
return SUCCESS;
}
return FAILURE;
}
/* }}} */
@@ -91,8 +127,11 @@ static PHP_INI_MH(OnSetExpectLogUser)
* */
static PHP_INI_MH(OnSetExpectLogFile)
{
if (EXPECT_G(logfile_stream)) {
php_stream_close(EXPECT_G(logfile_stream));
}
if (new_value_length > 0) {
php_stream *stream = php_stream_open_wrapper (new_value, "a", 0, NULL);
php_stream* stream = php_stream_open_wrapper (new_value, "a", 0, NULL);
if (!stream) {
php_error_docref (NULL TSRMLS_CC, E_ERROR, "could not open log file for writing");
return FAILURE;
@@ -101,8 +140,10 @@ static PHP_INI_MH(OnSetExpectLogFile)
if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void **) &exp_logfile, REPORT_ERRORS) != SUCCESS) {
return FAILURE;
}
EXPECT_G(logfile_stream) = stream;
exp_logfile_all = 1;
} else {
EXPECT_G(logfile_stream) = NULL;
exp_logfile = NULL;
exp_logfile_all = 0;
}
@@ -115,6 +156,7 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY("expect.timeout", "10", PHP_INI_ALL, OnSetExpectTimeout)
PHP_INI_ENTRY_EX("expect.loguser", "1", PHP_INI_ALL, OnSetExpectLogUser, php_ini_boolean_displayer_cb)
PHP_INI_ENTRY("expect.logfile", "", PHP_INI_ALL, OnSetExpectLogFile)
PHP_INI_ENTRY("expect.match_max", "5000", PHP_INI_ALL, OnSetExpectMatchMax)
PHP_INI_END()
@@ -131,6 +173,18 @@ PHP_MINIT_FUNCTION(expect)
REGISTER_LONG_CONSTANT("EXP_FULLBUFFER", EXP_FULLBUFFER, CONST_CS | CONST_PERSISTENT);
REGISTER_INI_ENTRIES();
Tcl_Interp *interp = Tcl_CreateInterp();
if (Tcl_Init(interp) == TCL_ERROR) {
php_error_docref (NULL TSRMLS_CC, E_ERROR,
"Unable to initialize TCL interpreter: %s", Tcl_GetStringResult (interp));
return FAILURE;
}
if (Expect_Init(interp) == TCL_ERROR) {
php_error_docref (NULL TSRMLS_CC, E_ERROR,
"Unable to initialize Expect: %s", Tcl_GetStringResult (interp));
return FAILURE;
}
return SUCCESS;
}
@@ -203,7 +257,7 @@ PHP_FUNCTION(expect_popen)
*/
PHP_FUNCTION(expect_expectl)
{
struct exp_case *ecases, *ec, matchedcase;
struct exp_case *ecases, *ecases_ptr, matchedcase;
zval *z_stream, *z_cases, *z_match=NULL, **z_case, **z_value;
php_stream *stream;
int fd, argc;
@@ -218,6 +272,8 @@ PHP_FUNCTION(expect_expectl)
php_stream_from_zval (stream, &z_stream);
if (!stream->wrapperdata) {
php_error_docref (NULL TSRMLS_CC, E_ERROR, "supplied argument is not a valid stream resource");
php_error_docref (NULL TSRMLS_CC, E_ERROR, "supplied argument is not a valid stream resource");
php_error_docref (NULL TSRMLS_CC, E_ERROR, "supplied argument is not a valid stream resource");
return;
}
@@ -228,8 +284,8 @@ PHP_FUNCTION(expect_expectl)
argc = zend_hash_num_elements (Z_ARRVAL_P(z_cases));
ecases = (struct exp_case*) safe_emalloc (argc + 1, sizeof(struct exp_case), 0);
ecases_ptr = ecases;
ec = ecases;
zend_hash_internal_pointer_reset (Z_ARRVAL_P(z_cases));
while (zend_hash_get_current_data (Z_ARRVAL_P(z_cases), (void **)&z_case) == SUCCESS)
@@ -243,8 +299,8 @@ PHP_FUNCTION(expect_expectl)
return;
}
ec->re = NULL;
ec->type = exp_glob;
ecases_ptr->re = NULL;
ecases_ptr->type = exp_glob;
/* Gather pattern */
if (zend_hash_index_find(Z_ARRVAL_PP(z_case), 0, (void **)&z_pattern) != SUCCESS) {
@@ -257,7 +313,7 @@ PHP_FUNCTION(expect_expectl)
php_error_docref (NULL TSRMLS_CC, E_ERROR, "pattern must be of string type");
return;
}
ec->pattern = Z_STRVAL_PP(z_pattern);
ecases_ptr->pattern = Z_STRVAL_PP(z_pattern);
/* Gather value */
if (zend_hash_index_find(Z_ARRVAL_PP(z_case), 1, (void **)&z_value) != SUCCESS) {
@@ -265,7 +321,7 @@ PHP_FUNCTION(expect_expectl)
php_error_docref (NULL TSRMLS_CC, E_ERROR, "missing parameter for value at index: 1");
return;
}
ec->value = key;
ecases_ptr->value = key;
/* Gather expression type (optional, default: EXPECT_GLOB) */
if (zend_hash_index_find(Z_ARRVAL_PP(z_case), 2, (void **)&z_exp_type) == SUCCESS) {
@@ -279,18 +335,21 @@ PHP_FUNCTION(expect_expectl)
php_error_docref (NULL TSRMLS_CC, E_ERROR, "expression type must be either EXPECT_GLOB, EXPECT_EXACT or EXPECT_REGEXP");
return;
}
ec->type = Z_LVAL_PP(z_exp_type);
ecases_ptr->type = Z_LVAL_PP(z_exp_type);
}
ec++;
ecases_ptr++;
zend_hash_move_forward(Z_ARRVAL_P(z_cases));
}
ec->type = exp_end;
ecases_ptr->pattern = NULL;
ecases_ptr->re = NULL;
ecases_ptr->value = NULL;
ecases_ptr->type = exp_end;
key = exp_expectv (fd, ecases);
int exp_match_len = exp_match_end - exp_match;
if (z_match && exp_match && exp_match_len > 0) {
if (key >= 0 && z_match && exp_match && exp_match_len > 0) {
char *tmp = (char *)emalloc (sizeof(char) * (exp_match_len + 1));
strlcpy (tmp, exp_match, exp_match_len + 1);
zval_dtor (z_match);
@@ -299,7 +358,7 @@ PHP_FUNCTION(expect_expectl)
/* Get case that was matched */
matchedcase = ecases[key];
/* If there are subpattern matches ... */
if (matchedcase.re->startp != NULL) {
if (matchedcase.re != NULL && matchedcase.re->startp != NULL) {
int i;
/* iterate across all possible 9 subpatterns (a limitation of libexpect)
and add matching substring to matches array */
@@ -326,6 +385,15 @@ PHP_FUNCTION(expect_expectl)
RETURN_LONG (key);
}
// Free compiled patterns:
ecases_ptr = ecases;
while (ecases_ptr != NULL && ecases_ptr->type != exp_end) {
if (ecases_ptr->re != NULL) {
free(ecases_ptr->re);
}
ecases_ptr++;
}
efree (ecases);
}
/* }}} */

View File

@@ -1,34 +1,54 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
<package>
<name>expect</name>
<summary>PHP extension for expect library</summary>
<description>This extension allows to interact with processes through PTY, using expect library.</description>
<license>PHP License</license>
<maintainers>
<maintainer>
<user>michael</user>
<name>Michael Spector</name>
<email>michael@php.net</email>
</maintainer>
</maintainers>
<release>
<version>0.2.5</version>
<date>2008-11-27</date>
<state>beta</state>
<notes>Fixed bug #14768 (configure error in Ubuntu 8.04)
</notes>
</release>
<filelist>
<dir role="doc" name="/">
<file role="src">config.m4</file>
<file role="src">expect.dsp</file>
<file role="src">config.w32</file>
<file role="src">expect.c</file>
<file role="src">expect_fopen_wrapper.c</file>
<file role="src">php_expect.h</file>
</dir>
</filelist>
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd
http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
<name>expect</name>
<channel>pecl.php.net</channel>
<summary>PHP extension for expect library</summary>
<description>This extension allows to interact with processes through PTY, using expect library.
</description>
<lead>
<name>Michael Spector</name>
<user>michael</user>
<email>michael@php.net</email>
<active>yes</active>
</lead>
<date>2011-06-23</date>
<time>23:40:00</time>
<version>
<release>0.3.0</release>
<api>0.3.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Fixed setting INI parameters (Bug #22566)
Fixed Segmentation Fault on use (Bug #21578)
</notes>
<contents>
<dir name="/">
<file name="config.m4" role="src" />
<file name="config.w32" role="src" />
<file name="expect.c" role="src" />
<file name="expect.dsp" role="src" />
<file name="expect_fopen_wrapper.c" role="src" />
<file name="php_expect.h" role="src" />
</dir> <!-- / -->
</contents>
<dependencies>
<required>
<php>
<min>4.0.0</min>
</php>
<pearinstaller>
<min>1.4.0b1</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>expect</providesextension>
<extsrcrelease />
</package>

View File

@@ -30,12 +30,14 @@
#include <SAPI.h>
#include <ext/standard/info.h>
#include <tcl.h>
#include <expect_tcl.h>
#include <expect.h>
extern zend_module_entry expect_module_entry;
#define phpext_expect_ptr &expect_module_entry
#define PHP_EXPECT_VERSION "0.2.5-dev"
#define PHP_EXPECT_VERSION "0.2.7-dev"
#ifdef PHP_WIN32
#define PHP_EXPECT_API __declspec(dllexport)
@@ -52,6 +54,16 @@ PHP_FUNCTION(expect_expectl);
extern php_stream_wrapper php_expect_wrapper;
ZEND_BEGIN_MODULE_GLOBALS(expect)
php_stream* logfile_stream;
ZEND_END_MODULE_GLOBALS(expect)
#ifdef ZTS
#define EXPECT_G(v) TSRMG(expect_globals_id, zend_expect_globals *, v)
#else
#define EXPECT_G(v) (expect_globals.v)
#endif
#ifdef ZTS
#include "TSRM.h"
#endif /* ZTS */

16
tests/bug22566.phpt Normal file
View File

@@ -0,0 +1,16 @@
--TEST--
PECL Bug #22566 CGI
--SKIPIF--
<?php if (!extension_loaded("expect")) print "skip"; ?>
--FILE--
<?php
var_dump(ini_set('expect.timeout', 3));
var_dump(ini_set('expect.match_max', '2000'));
var_dump(ini_get('expect.timeout'));
var_dump(ini_get('expect.match_max'));
?>
--EXPECT--
string(2) "10"
string(4) "5000"
string(1) "3"
string(4) "2000"