mirror of
https://github.com/php-win-ext/pecl-expect.git
synced 2026-03-24 05:02:05 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
178e5c07c5 | ||
|
|
9b925ac532 | ||
|
|
4411953272 | ||
|
|
f80a041dac |
65
expect.c
65
expect.c
@@ -87,7 +87,21 @@ 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;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -102,7 +116,9 @@ static PHP_INI_MH(OnSetExpectLogUser)
|
||||
} else {
|
||||
exp_loguser = 1;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -140,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()
|
||||
|
||||
|
||||
@@ -156,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;
|
||||
}
|
||||
@@ -228,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;
|
||||
@@ -243,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;
|
||||
}
|
||||
@@ -253,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)
|
||||
@@ -268,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) {
|
||||
@@ -282,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) {
|
||||
@@ -290,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) {
|
||||
@@ -304,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);
|
||||
@@ -324,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 */
|
||||
@@ -351,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);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
11
package.xml
11
package.xml
@@ -14,11 +14,11 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
||||
<email>michael@php.net</email>
|
||||
<active>yes</active>
|
||||
</lead>
|
||||
<date>2010-10-10</date>
|
||||
<time>09:28:00</time>
|
||||
<date>2011-06-23</date>
|
||||
<time>23:40:00</time>
|
||||
<version>
|
||||
<release>0.2.7</release>
|
||||
<api>0.2.7</api>
|
||||
<release>0.3.0</release>
|
||||
<api>0.3.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>beta</release>
|
||||
@@ -26,7 +26,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
||||
</stability>
|
||||
<license uri="http://www.php.net/license">PHP License</license>
|
||||
<notes>
|
||||
Fixed bug #18998 (Change expect.logfile on runtime leave file descriptor opened)
|
||||
Fixed setting INI parameters (Bug #22566)
|
||||
Fixed Segmentation Fault on use (Bug #21578)
|
||||
</notes>
|
||||
<contents>
|
||||
<dir name="/">
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#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;
|
||||
|
||||
16
tests/bug22566.phpt
Normal file
16
tests/bug22566.phpt
Normal 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"
|
||||
Reference in New Issue
Block a user