1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
31 extern zend_module_entry psi_module_entry
;
32 #define phpext_psi_ptr &psi_module_entry
34 #define PHP_PSI_VERSION "0.1.0"
37 # define PHP_PSI_API __declspec(dllexport)
38 #elif defined(__GNUC__) && __GNUC__ >= 4
39 # define PHP_PSI_API __attribute__ ((visibility("default")))
48 static inline int psi_check_env(const char *var
) {
49 char *set
= getenv(var
);
50 return (set
&& *set
&& (*set
!= '0' || set
[1]));
53 #include "php_network.h"
55 static inline int psi_fdopen(const char *desc
)
60 char *addr
= strstr(desc
, "://");
66 struct sockaddr_storage sa
= {0};
68 int rc
= php_network_parse_network_address_with_port(addr
,
69 strlen(addr
), (struct sockaddr
*) &sa
, &ss
);
72 int styp
= strncmp(desc
, "udp:", 4)
75 int sfam
= sa
.ss_family
== AF_INET6
76 ? ((struct sockaddr_in6
*) &sa
)->sin6_family
77 : ((struct sockaddr_in
*) &sa
)->sin_family
;
79 fd
= socket(sfam
, styp
, 0);
81 if (fd
> 0 && 0 != connect(fd
, (struct sockaddr
*) &sa
, ss
)) {
87 } else if (!strcmp(desc
, "stdout")) {
89 } else if (!strcmp(desc
, "stderr")) {
91 } else if (!(fd
= atoi(desc
)) || -1 == fcntl(fd
, F_GETFD
)) {
92 fd
= open(desc
, O_WRONLY
|O_APPEND
|O_CREAT
|O_CLOEXEC
, 0664);
98 typedef struct psi_object
{
100 void (*dtor
)(void *data
);
105 static inline psi_object
*PSI_OBJ(zval
*zv
, zend_object
*zo
) {
112 return (void *) (((char *) zo
) - zo
->handlers
->offset
);
115 PHP_PSI_API zend_object
*psi_object_init(zend_class_entry
*ce
);
116 PHP_PSI_API zend_object
*psi_object_init_ex(zend_class_entry
*ce
, void *data
, void (*dtor
)(void *));
117 PHP_PSI_API zend_class_entry
*psi_object_get_class_entry();
119 ZEND_BEGIN_MODULE_GLOBALS(psi
)
123 struct psi_context_ops
*ops
;
124 struct psi_context
*context
;
126 struct psi_plist
*decls
;
127 struct psi_plist
*vars
;
129 ZEND_END_MODULE_GLOBALS(psi
);
131 ZEND_EXTERN_MODULE_GLOBALS(psi
);
133 #define PSI_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(psi, v)
135 #if defined(ZTS) && defined(COMPILE_DL_PSI)
136 ZEND_TSRMLS_CACHE_EXTERN();
139 #endif /* PHP_PSI_H */
147 * vim600: noet sw=4 ts=4 fdm=marker
148 * vim<600: noet sw=4 ts=4