-1

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?

  • Possible duplicate of [PHP. Extension. Call existing PHP function](http://stackoverflow.com/questions/13592037/php-extension-call-existing-php-function) – Elias Nicolas Oct 22 '15 at 02:36

1 Answers1

0

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] = &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;
}