13 Commits
0.2.9 ... 0.3.3

Author SHA1 Message Date
michael
9ff8bd236f Upgraded PHP LICENSE to version 3.01. Released a new version.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@337814 c90b9560-bf6c-de11-be94-00142212c4b1
2015-09-11 17:46:51 +00:00
remi
962f488073 fix global init/shudown (segfault on ZTS build)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@337812 c90b9560-bf6c-de11-be94-00142212c4b1
2015-09-11 16:02:10 +00:00
remi
7e6b652293 add LICENSE + missing files in package.xml
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@337811 c90b9560-bf6c-de11-be94-00142212c4b1
2015-09-11 15:32:52 +00:00
remi
6fafe17e77 set max version as not yet compatible with php 7
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@337810 c90b9560-bf6c-de11-be94-00142212c4b1
2015-09-11 15:19:21 +00:00
remi
18ea03b802 fix build when PHP_LIBDIR = lib64 (RPM distro)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@337809 c90b9560-bf6c-de11-be94-00142212c4b1
2015-09-11 15:15:49 +00:00
michael
a291a8ff3b Increment version
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@337808 c90b9560-bf6c-de11-be94-00142212c4b1
2015-09-11 12:31:25 +00:00
michael
48d03837f9 Fixed #70458
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@337807 c90b9560-bf6c-de11-be94-00142212c4b1
2015-09-11 12:29:29 +00:00
michael
5fdde4afbf Fixed setting boolea value "expect.loguser"
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@334336 c90b9560-bf6c-de11-be94-00142212c4b1
2014-07-20 16:29:12 +00:00
michael
98a048f820 Fixed compilation issues (bug #59916)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@319689 c90b9560-bf6c-de11-be94-00142212c4b1
2011-11-22 16:27:35 +00:00
michael
c02699dde7 removed duplicate print added in previous commit by mistake
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@312460 c90b9560-bf6c-de11-be94-00142212c4b1
2011-06-25 15:42:54 +00:00
michael
8133790622 Updated e-mail address
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@312443 c90b9560-bf6c-de11-be94-00142212c4b1
2011-06-24 19:35:30 +00:00
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
7 changed files with 225 additions and 63 deletions

68
LICENSE Normal file
View File

@@ -0,0 +1,68 @@
--------------------------------------------------------------------
The PHP License, version 3.01
Copyright (c) 1999 - 2014 The PHP Group. All rights reserved.
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, is permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name "PHP" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact group@php.net.
4. Products derived from this software may not be called "PHP", nor
may "PHP" appear in their name, without prior written permission
from group@php.net. You may indicate that your software works in
conjunction with PHP by saying "Foo for PHP" instead of calling
it "PHP Foo" or "phpfoo"
5. The PHP Group may publish revised and/or new versions of the
license from time to time. Each version will be given a
distinguishing version number.
Once covered code has been published under a particular version
of the license, you may always continue to use it under the terms
of that version. You may also choose to use such covered code
under the terms of any subsequent version of the license
published by the PHP Group. No one other than the PHP Group has
the right to modify the terms applicable to covered code created
under this License.
6. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes PHP software, freely available from
<http://www.php.net/software/>".
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------
This software consists of voluntary contributions made by many
individuals on behalf of the PHP Group.
The PHP Group can be contacted via Email at group@php.net.
For more information on the PHP Group and the PHP project,
please see <http://www.php.net>.
PHP includes the Zend Engine, freely available at
<http://www.zend.com>.

View File

@@ -5,6 +5,9 @@ dnl
PHP_ARG_WITH(expect,for expect support,
[ --with-expect[=DIR] Include expect support (requires libexpect >= 5.43.0).])
PHP_ARG_WITH(tcldir,specify path to Tcl needed by expect,
[ --with-tcldir[=DIR] Specify path to Tcl config script (tclConfig.sh).])
if test "$PHP_EXPECT" != "no"; then
for i in $PHP_EXPECT/include/expect.h $PHP_EXPECT/include/*/expect.h \
@@ -18,9 +21,28 @@ if test "$PHP_EXPECT" != "no"; then
fi
done
PHP_ADD_LIBRARY_WITH_PATH(expect, $LIBEXPECT_DIR/lib, EXPECT_SHARED_LIBADD)
AC_MSG_CHECKING(for tcl version)
for i in $PHP_TCLDIR/tclConfig.sh /usr/lib/tcl*/tclConfig.sh \
/usr/$PHP_LIBDIR/tcl*/tclConfig.sh \
/usr/local/lib/tcl*/tclConfig.sh \
/System/Library/Frameworks/Tcl.framework/Versions/Current/tclConfig.sh;
do
if test -f $i; then
. $i
break
fi
done
if test -n "$TCL_VERSION" ; then
AC_MSG_RESULT($TCL_VERSION in $TCL_PREFIX)
else
AC_MSG_ERROR([not found])
fi
PHP_ADD_LIBRARY_WITH_PATH(tcl$TCL_VERSION, $TCL_PREFIX/$PHP_LIBDIR, EXPECT_SHARED_LIBADD)
PHP_ADD_LIBRARY_WITH_PATH(expect, $LIBEXPECT_DIR/$PHP_LIBDIR, EXPECT_SHARED_LIBADD)
PHP_ADD_INCLUDE($LIBEXPECT_INCLUDE_DIR)
PHP_NEW_EXTENSION(expect, expect.c expect_fopen_wrapper.c, $ext_shared)
PHP_SUBST(EXPECT_SHARED_LIBADD)
fi

148
expect.c
View File

@@ -12,7 +12,7 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Michael Spector <michael@zend.com> |
| Author: Michael Spector <michael@php.net> |
+----------------------------------------------------------------------+
*/
@@ -41,6 +41,10 @@ zend_function_entry expect_functions[] = {
/* }}} */
ZEND_DECLARE_MODULE_GLOBALS(expect)
static PHP_GINIT_FUNCTION(expect);
static PHP_GSHUTDOWN_FUNCTION(expect);
/* {{{ expect_module_entry
*/
zend_module_entry expect_module_entry = {
@@ -53,7 +57,11 @@ zend_module_entry expect_module_entry = {
NULL,
PHP_MINFO(expect),
PHP_EXPECT_VERSION,
STANDARD_MODULE_PROPERTIES
PHP_MODULE_GLOBALS(expect),
PHP_GINIT(expect),
PHP_GSHUTDOWN(expect),
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
@@ -61,22 +69,20 @@ 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)
static PHP_GINIT_FUNCTION(expect)
{
globals->logfile_stream = NULL;
expect_globals->logfile_stream = NULL;
}
/* }}} */
/* {{{ php_expect_destroy_globals
*/
static void php_expect_destroy_globals(zend_expect_globals *globals TSRMLS_DC)
static PHP_GSHUTDOWN_FUNCTION(expect)
{
if (globals->logfile_stream) {
php_stream_close(globals->logfile_stream);
if (expect_globals->logfile_stream) {
php_stream_close(expect_globals->logfile_stream);
}
}
/* }}} */
@@ -87,7 +93,9 @@ static PHP_INI_MH(OnSetExpectTimeout)
{
if (new_value) {
exp_timeout = atoi(new_value);
return SUCCESS;
}
return FAILURE;
}
/* }}} */
@@ -97,7 +105,9 @@ static PHP_INI_MH(OnSetExpectMatchMax)
{
if (new_value) {
exp_match_max = atoi(new_value);
return SUCCESS;
}
return FAILURE;
}
/* }}} */
@@ -107,12 +117,17 @@ static PHP_INI_MH(OnSetExpectMatchMax)
static PHP_INI_MH(OnSetExpectLogUser)
{
if (new_value) {
if (strncasecmp("on", new_value, sizeof("on"))) {
exp_loguser = atoi(new_value);
} else {
if (strncasecmp("on", new_value, sizeof("on")) == 0
|| strncasecmp("true", new_value, sizeof("true")) == 0
|| strncasecmp("yes", new_value, sizeof("yes")) == 0
|| strncasecmp("1", new_value, sizeof("1")) == 0) {
exp_loguser = 1;
} else {
exp_loguser = 0;
}
return SUCCESS;
}
return FAILURE;
}
/* }}} */
@@ -167,6 +182,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;
}
@@ -239,7 +266,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;
@@ -264,8 +291,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)
@@ -279,8 +306,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) {
@@ -293,7 +320,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) {
@@ -301,7 +328,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) {
@@ -315,54 +342,71 @@ 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 = 0;
ecases_ptr->type = exp_end;
key = exp_expectv (fd, ecases);
int exp_retval = exp_expectv (fd, ecases);
int case_found = 0;
if (exp_retval >= 0) {
key = exp_retval;
int exp_match_len = exp_match_end - exp_match;
if (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);
array_init(z_match);
add_index_string(z_match, 0, tmp, 1);
/* Get case that was matched */
matchedcase = ecases[key];
/* If there are subpattern matches ... */
if (matchedcase.re->startp != NULL) {
int i;
/* iterate across all possible 9 subpatterns (a limitation of libexpect)
and add matching substring to matches array */
for (i = 1; i <= 9; i++) {
if (matchedcase.re->startp[i] != NULL) {
int sub_match_len = matchedcase.re->endp[i] - matchedcase.re->startp[i];
char *sub_match = (char *)emalloc (sizeof(char) * (sub_match_len + 1));
strlcpy (sub_match, matchedcase.re->startp[i], sub_match_len + 1);
add_next_index_string(z_match, sub_match, 1);
efree (sub_match);
int exp_match_len = exp_match_end - exp_match;
if (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);
array_init(z_match);
add_index_string(z_match, 0, tmp, 1);
/* Get case that was matched */
matchedcase = ecases[key];
/* If there are subpattern matches ... */
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 */
for (i = 1; i <= 9; i++) {
if (matchedcase.re->startp[i] != NULL) {
int sub_match_len = matchedcase.re->endp[i] - matchedcase.re->startp[i];
char *sub_match = (char *)emalloc (sizeof(char) * (sub_match_len + 1));
strlcpy (sub_match, matchedcase.re->startp[i], sub_match_len + 1);
add_next_index_string(z_match, sub_match, 1);
efree (sub_match);
}
}
}
efree (tmp);
}
efree (tmp);
}
if (zend_hash_index_find (Z_ARRVAL_P(z_cases), key, (void **)&z_case) == SUCCESS) {
if (zend_hash_index_find(Z_ARRVAL_PP(z_case), 1, (void **)&z_value) == SUCCESS) {
*return_value = **z_value;
zval_copy_ctor (return_value);
if (zend_hash_index_find (Z_ARRVAL_P(z_cases), key, (void **)&z_case) == SUCCESS) {
if (zend_hash_index_find(Z_ARRVAL_PP(z_case), 1, (void **)&z_value) == SUCCESS) {
*return_value = **z_value;
zval_copy_ctor (return_value);
case_found = 1;
}
}
}
else {
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);
if (!case_found) {
RETURN_LONG(exp_retval);
}
}
/* }}} */

View File

@@ -12,7 +12,7 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Michael Spector <michael@zend.com> |
| Author: Michael Spector <michael@php.net> |
+----------------------------------------------------------------------+
*/

View File

@@ -14,19 +14,19 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>michael@php.net</email>
<active>yes</active>
</lead>
<date>2011-01-25</date>
<time>23:07:00</time>
<date>2015-09-11</date>
<time>15:25:00</time>
<version>
<release>0.2.9</release>
<api>0.2.9</api>
<release>0.3.3</release>
<api>0.3.3</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Provide a default value for expect.match_max (Bug #21823)
Added LICENSE. Fixed RPM build for 64bit.
</notes>
<contents>
<dir name="/">
@@ -36,12 +36,22 @@ Provide a default value for expect.match_max (Bug #21823)
<file name="expect.dsp" role="src" />
<file name="expect_fopen_wrapper.c" role="src" />
<file name="php_expect.h" role="src" />
<file name="LICENSE" role="doc" />
<dir name="tests">
<file name="bug12268.phpt" role="test" />
<file name="bug22566.phpt" role="test" />
<file name="bug6996.phpt" role="test" />
<file name="expect_expectl.phpt" role="test" />
<file name="expect_popen.phpt" role="test" />
<file name="expect_wrapper.phpt" role="test" />
</dir>
</dir> <!-- / -->
</contents>
<dependencies>
<required>
<php>
<min>4.0.0</min>
<max>5.99.99</max>
</php>
<pearinstaller>
<min>1.4.0b1</min>

View File

@@ -12,7 +12,7 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Michael Spector <michael@zend.com> |
| Author: Michael Spector <michael@php.net> |
+----------------------------------------------------------------------+
*/
@@ -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.7-dev"
#define PHP_EXPECT_VERSION "0.3.3"
#ifdef PHP_WIN32
#define PHP_EXPECT_API __declspec(dllexport)

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"