I'm writing a PHP extension and wanted to call openssl extension functions from my extension, to be specific, I want to call openssl_x509_read function from inside my extension. Is it possible? And how do I do it?
Found the answear, here's how to call the function openssl_x509_read from your module:
#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;
}