PHP 扩展调用另一个扩展函数
PHP extension calling another extension function
我正在写一个 PHP 扩展,想从我的扩展中调用 openssl 扩展函数,具体来说,我想从我的扩展中调用 openssl_x509_read 函数。
可能吗?我该怎么做?
找到答案,下面是如何从您的模块调用函数 openssl_x509_read:
#define FUNC_OPENSSL_X509_READ "openssl_x509_read"
zval *openssl_x509_read(unsigned char *certificate_data, int certificate_data_length) {
zval *function_name, *certificate, *param_certificate, **params[1];
TSRMLS_FETCH();
MAKE_STD_ZVAL(function_name);
ZVAL_STRINGL(function_name, FUNC_OPENSSL_X509_READ,
strlen(FUNC_OPENSSL_X509_READ), 0);
MAKE_STD_ZVAL(param_certificate);
ZVAL_STRINGL(param_certificate, certificate_data, certificate_data_length,
0);
params[0] = ¶m_certificate;
if (call_user_function_ex(CG(function_table), NULL, function_name,
&certificate, 1, params, 0, NULL TSRMLS_CC) != SUCCESS) {
zend_error(E_ERROR, "Function openssl_x509_read failed");
return NULL;
}
FREE_ZVAL(function_name);
FREE_ZVAL(param_certificate);
return certificate;
}
我正在写一个 PHP 扩展,想从我的扩展中调用 openssl 扩展函数,具体来说,我想从我的扩展中调用 openssl_x509_read 函数。 可能吗?我该怎么做?
找到答案,下面是如何从您的模块调用函数 openssl_x509_read:
#define FUNC_OPENSSL_X509_READ "openssl_x509_read"
zval *openssl_x509_read(unsigned char *certificate_data, int certificate_data_length) {
zval *function_name, *certificate, *param_certificate, **params[1];
TSRMLS_FETCH();
MAKE_STD_ZVAL(function_name);
ZVAL_STRINGL(function_name, FUNC_OPENSSL_X509_READ,
strlen(FUNC_OPENSSL_X509_READ), 0);
MAKE_STD_ZVAL(param_certificate);
ZVAL_STRINGL(param_certificate, certificate_data, certificate_data_length,
0);
params[0] = ¶m_certificate;
if (call_user_function_ex(CG(function_table), NULL, function_name,
&certificate, 1, params, 0, NULL TSRMLS_CC) != SUCCESS) {
zend_error(E_ERROR, "Function openssl_x509_read failed");
return NULL;
}
FREE_ZVAL(function_name);
FREE_ZVAL(param_certificate);
return certificate;
}