Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion packages/php-wasm/compile/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,17 @@ await cleanupOldMinorVersions();
// Build the base image
await asyncSpawn('make', ['base-image'], { cwd: sourceDir, stdio: 'inherit' });

const phpVersionForDockerfile = getArg('PHP_VERSION').replace('PHP_VERSION=', '');
const dockerfile = phpVersionForDockerfile.startsWith('5.2')
? 'php/Dockerfile-5-2'
: 'php/Dockerfile';

await asyncSpawn(
'docker',
[
'build',
'-f',
'php/Dockerfile',
dockerfile,
'..',
'--tag=php-wasm',
'--progress=plain',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "ext/standard/info.h"
#include <emscripten.h>

/* PHP_FE_END was added in PHP 5.3.7; provide fallback for PHP 5.2 */
#ifndef PHP_FE_END
#define PHP_FE_END {NULL, NULL, NULL}
#endif

/**
* Provided by php_wasm.c:
*/
Expand All @@ -14,16 +19,22 @@ PHP_FUNCTION(post_message_to_js)
char *data;
int data_len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data, &data_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) {
return;
}

char *response;
size_t response_len = js_module_onMessage(data, &response);
if (response_len != -1) {
if (response_len != (size_t)-1) {
#if PHP_MAJOR_VERSION >= 7
zend_string *return_string = zend_string_init(response, response_len, 0);
free(response);
RETURN_NEW_STR(return_string);
#else
RETVAL_STRINGL(response, response_len, 1);
free(response);
return;
#endif
} else {
RETURN_NULL();
}
Expand All @@ -39,6 +50,12 @@ PHP_MINFO_FUNCTION(post_message_to_js)
}
/* }}} */

/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_post_message_to_js, 0, 1, 1)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
/* }}} */

/* {{{ post_message_to_js_functions[] */
const zend_function_entry post_message_to_js_functions[] = {
PHP_FE(post_message_to_js, arginfo_post_message_to_js)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
extern zend_module_entry post_message_to_js_module_entry;
#define phpext_post_message_to_js_ptr &post_message_to_js_module_entry

ZEND_BEGIN_ARG_INFO_EX(arginfo_post_message_to_js, 0, 1, 1)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()

PHP_FUNCTION(post_message_to_js);

#define PHP_POST_MESSAGE_TO_JS_VERSION "1.0.0"
Expand Down
63 changes: 57 additions & 6 deletions packages/php-wasm/compile/php-wasm-dns-polyfill/dns_polyfill.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "dns_polyfill.h"
#include "ext/standard/info.h"

/* ZEND_FE_END was added in PHP 5.3.7; provide fallback for PHP 5.2 */
#ifndef ZEND_FE_END
#define ZEND_FE_END {NULL, NULL, NULL}
#endif

#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
Expand Down Expand Up @@ -119,21 +124,27 @@ PHP_FUNCTION(dns_check_record)
HEADER *hp;
querybuf answer = {0};
char *hostname;
#if PHP_MAJOR_VERSION >= 7
size_t hostname_len;
size_t rectype_len = 0;
zend_string *rectype = NULL;
#else
int hostname_len;
int rectype_len = 0;
char *rectype = NULL;
#endif
int type = DNS_T_MX, i;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &hostname, &hostname_len, &rectype, &rectype_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &hostname, &hostname_len, &rectype, &rectype_len) == FAILURE) {
return;
}

if (hostname_len == 0) {
php_error_docref(NULL, E_WARNING, "Host cannot be empty");
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host cannot be empty");
RETURN_FALSE;
}

php_error_docref(NULL, E_WARNING, "dns_check_record() always returns false in PHP.wasm.");
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dns_check_record() always returns false in PHP.wasm.");

RETURN_FALSE;
}
Expand All @@ -143,8 +154,13 @@ PHP_FUNCTION(dns_check_record)
PHP_FUNCTION(dns_get_record)
{
char *hostname;
#if PHP_MAJOR_VERSION >= 7
size_t hostname_len;
zend_long type_param = PHP_DNS_ANY;
#else
int hostname_len;
long type_param = PHP_DNS_ANY;
#endif
zval *authns = NULL, *addtl = NULL;
int type_to_fetch;
int dns_errno;
Expand All @@ -155,7 +171,7 @@ PHP_FUNCTION(dns_get_record)
int type, first_query = 1, store_results = 1;
zend_bool raw = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lz!z!b",
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz!z!b",
&hostname, &hostname_len, &type_param, &authns, &addtl, &raw) == FAILURE) {
return;
}
Expand All @@ -173,7 +189,7 @@ PHP_FUNCTION(dns_get_record)
}
}

php_error_docref(NULL, E_WARNING, "dns_get_record() always returns an empty array in PHP.wasm.");
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dns_get_record() always returns an empty array in PHP.wasm.");

/* Initialize the return array */
array_init(return_value);
Expand All @@ -186,7 +202,11 @@ PHP_FUNCTION(dns_get_record)
PHP_FUNCTION(dns_get_mx)
{
char *hostname;
#if PHP_MAJOR_VERSION >= 7
size_t hostname_len;
#else
int hostname_len;
#endif
zval *mx_list, *weight_list = NULL;
int count, qdc;
u_short type, weight;
Expand All @@ -196,12 +216,18 @@ PHP_FUNCTION(dns_get_mx)
uint8_t *cp, *end;
int i;

#if PHP_MAJOR_VERSION >= 7
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(hostname, hostname_len)
Z_PARAM_ZVAL(mx_list)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(weight_list)
ZEND_PARSE_PARAMETERS_END();
#else
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|z", &hostname, &hostname_len, &mx_list, &weight_list) == FAILURE) {
return;
}
#endif

array_init(mx_list);
if (!mx_list) {
Expand All @@ -215,7 +241,7 @@ PHP_FUNCTION(dns_get_mx)
}
}

php_error_docref(NULL, E_WARNING, "dns_get_mx() always returns an empty array in PHP.wasm.");
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dns_get_mx() always returns an empty array in PHP.wasm.");

RETURN_FALSE;
}
Expand Down Expand Up @@ -256,6 +282,31 @@ PHP_MSHUTDOWN_FUNCTION(dns_polyfill)
return SUCCESS;
}

/* {{{ arginfo definitions */
ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_check_record, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()

#define arginfo_checkdnsrr arginfo_dns_check_record

ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_get_record, 0, 0, 1)
ZEND_ARG_INFO(0, hostname)
ZEND_ARG_INFO(0, type)
ZEND_ARG_ARRAY_INFO(1, authns, 1)
ZEND_ARG_ARRAY_INFO(1, addtl, 1)
ZEND_ARG_INFO(0, raw)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_get_mx, 0, 0, 2)
ZEND_ARG_INFO(0, hostname)
ZEND_ARG_INFO(1, mxhosts)
ZEND_ARG_INFO(1, weight)
ZEND_END_ARG_INFO()

#define arginfo_getmxrr arginfo_dns_get_mx
/* }}} */

/* {{{ dns_polyfill_functions[] */
const zend_function_entry dns_polyfill_functions[] = {
ZEND_FE(dns_get_mx, arginfo_dns_get_mx)
Expand Down
25 changes: 0 additions & 25 deletions packages/php-wasm/compile/php-wasm-dns-polyfill/dns_polyfill.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,8 @@
extern zend_module_entry dns_polyfill_module_entry;
#define phpext_dns_polyfill_ptr &dns_polyfill_module_entry

ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_check_record, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()

#define arginfo_checkdnsrr arginfo_dns_check_record

PHP_FUNCTION(dns_check_record);

ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_get_record, 0, 0, 1)
ZEND_ARG_INFO(0, hostname)
ZEND_ARG_INFO(0, type)
ZEND_ARG_ARRAY_INFO(1, authns, 1)
ZEND_ARG_ARRAY_INFO(1, addtl, 1)
ZEND_ARG_INFO(0, raw)
ZEND_END_ARG_INFO()

PHP_FUNCTION(dns_get_record);

ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_get_mx, 0, 0, 2)
ZEND_ARG_INFO(0, hostname)
ZEND_ARG_INFO(1, mxhosts) /* ARRAY_INFO(1, mxhosts, 1) */
ZEND_ARG_INFO(1, weight) /* ARRAY_INFO(1, weight, 1) */
ZEND_END_ARG_INFO()

#define arginfo_getmxrr arginfo_dns_get_mx

PHP_FUNCTION(dns_get_mx);

#define PHP_DNS_POLYFILL_VERSION "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "Zend/zend_alloc.h"
#include "php_wasm_memory_storage.h"

#if PHP_MAJOR_VERSION >= 7

/**
* Allocate a chunk of memory.
*
Expand Down Expand Up @@ -112,6 +114,22 @@ PHP_MSHUTDOWN_FUNCTION(wasm_memory_storage)
return SUCCESS;
}

#else /* PHP < 7 */

/* Custom memory storage is not available in PHP 5.x.
* Provide no-op MINIT/MSHUTDOWN. */
PHP_MINIT_FUNCTION(wasm_memory_storage)
{
return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(wasm_memory_storage)
{
return SUCCESS;
}

#endif /* PHP_MAJOR_VERSION >= 7 */

/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(wasm_memory_storage)
{
Expand Down
Loading
Loading