X-Git-Url: https://mop.ddnsfree.com/gitweb/?p=php-ancillary.git;a=blobdiff_plain;f=php-ancillary.c;h=115221a9dca142774f850dd810793e003d5d571f;hp=be249c9a28716625541f27c6dff6f08990bc4331;hb=d01d2155a49053f403e038b05ff7623d8efd3ea7;hpb=5f3d6c49a07662e84b39bc99be7cfc2d5f10b70e diff --git a/php-ancillary.c b/php-ancillary.c index be249c9..115221a 100644 --- a/php-ancillary.c +++ b/php-ancillary.c @@ -2,6 +2,7 @@ #include "config.h" #endif #include "php.h" +#include #define PHP_ANCILLARY_VERSION "1.0" #define PHP_ANCILLARY_EXTNAME "ancillary" @@ -10,12 +11,12 @@ extern zend_module_entry ancillary_module_entry; #define phpext_ancillary_ptr &ancillary_module_entry // declaration of a custom mop_function() -PHP_FUNCTION(mop_function); +PHP_FUNCTION(ancillary_getstream); // list of custom PHP functions provided by this extension // set {NULL, NULL, NULL} as the last record to mark the end of list -static function_entry mop_functions[] = { - PHP_FE(mop_function, NULL) +static function_entry ancillary_getstream[] = { + PHP_FE(ancillary_getstream, NULL) {NULL, NULL, NULL} }; @@ -25,7 +26,7 @@ zend_module_entry ancillary_module_entry = { STANDARD_MODULE_HEADER, #endif PHP_ANCILLARY_EXTNAME, - mop_functions, + ancillary_getstream, NULL, // name of the MINIT function or NULL if not applicable NULL, // name of the MSHUTDOWN function or NULL if not applicable NULL, // name of the RINIT function or NULL if not applicable @@ -39,8 +40,30 @@ zend_module_entry ancillary_module_entry = { ZEND_GET_MODULE(ancillary) -// implementation of a custom mop_function() -PHP_FUNCTION(mop_function) +// starting from a unix socket receive a socket from an external process +PHP_FUNCTION(ancillary_getstream) { - RETURN_STRING("This is my function", 1); + zval *zstream; + php_stream *stream; + int fd_in, fd_out; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream)) + return; + + php_stream_from_zval(stream, &zstream); + + if (php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd_in, REPORT_ERRORS) == FAILURE) { + RETURN_FALSE; + } + + if(ancil_recv_fd(fd_in, &fd_out)) { + RETURN_FALSE; + } + + if ((stream = php_stream_fopen_from_fd(fd_out, "r+b", NULL)) == NULL) { + RETURN_FALSE; + } + + php_stream_to_zval(stream, return_value); } +