PHP扩展调用另一个扩展函数

时间:2015-10-07 17:08:13

标签: php php-extension php-openssl

我正在编写PHP扩展并想从我的扩展中调用openssl扩展函数,具体来说,我想从我的扩展中调用openssl_x509_read函数。 可能吗?我该怎么做?

1 个答案:

答案 0 :(得分:0)

找到了answear,这是如何从你的模块调用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] = &param_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;
}