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]));
54 #include "php_network.h"
56 static inline int psi_fdopen(const char *desc
)
61 char *addr
= strstr(desc
, "://");
67 struct sockaddr_storage sa
= {0};
69 int rc
= php_network_parse_network_address_with_port(addr
,
70 strlen(addr
), (struct sockaddr
*) &sa
, &ss
);
73 int styp
= strncmp(desc
, "udp:", 4)
76 int sfam
= sa
.ss_family
== AF_INET6
77 ? ((struct sockaddr_in6
*) &sa
)->sin6_family
78 : ((struct sockaddr_in
*) &sa
)->sin_family
;
80 fd
= socket(sfam
, styp
, 0);
82 if (fd
> 0 && 0 != connect(fd
, (struct sockaddr
*) &sa
, ss
)) {
88 } else if (!strcmp(desc
, "stdout")) {
90 } else if (!strcmp(desc
, "stderr")) {
92 } else if (!(fd
= atoi(desc
)) || -1 == fcntl(fd
, F_GETFD
)) {
93 fd
= open(desc
, O_WRONLY
|O_APPEND
|O_CREAT
|O_CLOEXEC
, 0664);
99 typedef struct psi_object
{
101 void (*dtor
)(void *data
);
106 static inline psi_object
*PSI_OBJ(zval
*zv
, zend_object
*zo
) {
113 return (void *) (((char *) zo
) - zo
->handlers
->offset
);
116 PHP_PSI_API zend_object
*psi_object_init(zend_class_entry
*ce
);
117 PHP_PSI_API zend_object
*psi_object_init_ex(zend_class_entry
*ce
, void *data
, void (*dtor
)(void *));
118 PHP_PSI_API zend_class_entry
*psi_object_get_class_entry();
120 void psi_blacklist_add_decl(const char *pattern
, size_t len
);
121 void psi_blacklist_add_var(const char *pattern
, size_t len
);
123 ZEND_BEGIN_MODULE_GLOBALS(psi
)
127 struct psi_context_ops
*ops
;
128 struct psi_context
*context
;
130 struct psi_plist
*decls
;
131 struct psi_plist
*vars
;
133 ZEND_END_MODULE_GLOBALS(psi
);
135 ZEND_EXTERN_MODULE_GLOBALS(psi
);
137 #define PSI_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(psi, v)
139 #if defined(ZTS) && defined(COMPILE_DL_PSI)
140 ZEND_TSRMLS_CACHE_EXTERN();
143 #endif /* PHP_PSI_H */
151 * vim600: noet sw=4 ts=4 fdm=marker
152 * vim<600: noet sw=4 ts=4