Skip to content

Commit 378055d

Browse files
committed
first php7 version
1 parent a7b7d00 commit 378055d

10 files changed

+144
-54
lines changed

GetPathDir.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
// Retrieves the pathpath from a pathname.
2323
//
24-
// Returns: SUCCESS if the basepath is present and successfully copied to the p_base_path buffer
25-
// FAILURE_NULL_ARGUMENT if any arguments are NULL
26-
// FAILURE_INVALID_ARGUMENTS if either buffer size is less than 1
27-
// FAILURE_BUFFER_TOO_SMALL if the p_basepath buffer is too small
28-
// FAILURE_INVALID_PATH if the p_pathname doesn't have a path (e.g. C:, calc.exe, ?qwa)
29-
// FAILURE_API_CALL if there is an error from the underlying API calls
24+
// Returns: MCA_SUCCESS if the basepath is present and successfully copied to the p_base_path buffer
25+
// MCA_FAILURE_NULL_ARGUMENT if any arguments are NULL
26+
// MCA_FAILURE_INVALID_ARGUMENTS if either buffer size is less than 1
27+
// MCA_FAILURE_BUFFER_TOO_SMALL if the p_basepath buffer is too small
28+
// MCA_FAILURE_INVALID_PATH if the p_pathname doesn't have a path (e.g. C:, calc.exe, ?qwa)
29+
// MCA_FAILURE_API_CALL if there is an error from the underlying API calls
3030
int get_base_path_from_pathname( const char* const p_pathname,
3131
size_t pathname_size,
3232
char* const p_basepath,
@@ -37,28 +37,28 @@ int get_base_path_from_pathname( const char* const p_pathname,
3737
int return_code;
3838

3939
// Parameter Validation
40-
if( p_pathname == NULL || p_basepath == NULL ) { return FAILURE_NULL_ARGUMENT; }
41-
if( pathname_size < 1 || basepath_size < 1 ) { return FAILURE_INVALID_ARGUMENTS; }
40+
if( p_pathname == NULL || p_basepath == NULL ) { return MCA_FAILURE_NULL_ARGUMENT; }
41+
if( pathname_size < 1 || basepath_size < 1 ) { return MCA_FAILURE_INVALID_ARGUMENTS; }
4242

4343
// Returns a pointer to the last occurrence of \ in p_pathname or NULL if it is not found
4444
p_end_of_path = strrchr( p_pathname, '/' );
4545
if( p_end_of_path == NULL )
4646
{
4747
// There is no path part
48-
return FAILURE_INVALID_PATH;
48+
return MCA_FAILURE_INVALID_PATH;
4949
}
5050
else
5151
{
5252
path_length = (size_t)( p_end_of_path - p_pathname + 1 );
5353

5454
// Do some sanity checks on the length
55-
if( path_length < 1 ) { return FAILURE_INVALID_PATH; }
56-
if( ( path_length + 1 ) > basepath_size ) { return FAILURE_BUFFER_TOO_SMALL; }
55+
if( path_length < 1 ) { return MCA_FAILURE_INVALID_PATH; }
56+
if( ( path_length + 1 ) > basepath_size ) { return MCA_FAILURE_BUFFER_TOO_SMALL; }
5757

5858
// Copy the base path into the out variable
5959
strncpy(p_basepath, p_pathname, path_length);
6060
p_basepath[path_length] = '\0';
6161
}
6262

63-
return SUCCESS;
63+
return MCA_SUCCESS;
6464
}

GetPathDir.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
#include <stdio.h>
2525
#include <stdlib.h>
2626

27-
#define FAILURE_NULL_ARGUMENT 1
28-
#define FAILURE_INVALID_ARGUMENTS 2
29-
#define FAILURE_INVALID_PATH 3
30-
#define FAILURE_BUFFER_TOO_SMALL 4
31-
#define FAILURE_API_CALL 5
32-
#define SUCCESS 0
27+
#define MCA_FAILURE_NULL_ARGUMENT 1
28+
#define MCA_FAILURE_INVALID_ARGUMENTS 2
29+
#define MCA_FAILURE_INVALID_PATH 3
30+
#define MCA_FAILURE_BUFFER_TOO_SMALL 4
31+
#define MCA_FAILURE_API_CALL 5
32+
#define MCA_SUCCESS 0
3333
extern int get_base_path_from_pathname( const char* const p_pathname,
3434
size_t pathname_size,
3535
char* const p_basepath,

Makefile.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MODULE_NAME=@MODULE_NAME@
2-
MODULE_OBJS=$(MODULE_NAME).o php_embeded.o GetPathDir.o
3-
CFLAGS=-fPIC -I@ZABBIX_INC_DIR@ @CFLAGS@
2+
MODULE_OBJS=php_embeded.o GetPathDir.o $(MODULE_NAME).o
3+
CFLAGS=-fPIC -I@ZABBIX_INC_DIR@ @CFLAGS@ -Wno-cpp
44
LDFLAGS=@LDFLAGS@
55
LIBS=@LIBS@
66
CC=gcc

configure.ac

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ AC_SUBST([LDFLAGS])
4343
AC_SUBST([LIBS])
4444
AC_SUBST([prefix])
4545

46-
AC_OUTPUT(zbx_php_config.h Makefile)
46+
AC_CONFIG_HEADER(zbx_php_config.h)
47+
AC_OUTPUT(Makefile)
4748

4849
echo ""
4950
echo " Zabbix PHP laodable module install diretory = ${prefix}"

m4/ax_lib_php.m4

+7-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ AC_HELP_STRING([--with-php_lib@<:@=DIR@:>@], [PHP lib subdirectory if different
8585
PHP_VERSION=""
8686
8787
dnl
88-
dnl Check PHP Embeded libraries (libphp5)
88+
dnl Check PHP Embeded libraries (libphp)
8989
dnl
9090
9191
if test "$want_php" = "yes"; then
@@ -106,8 +106,11 @@ AC_HELP_STRING([--with-php_lib@<:@=DIR@:>@], [PHP lib subdirectory if different
106106
LDFLAGS="${LDFLAGS} ${PHP_LDFLAGS}"
107107
CFLAGS="${CFLAGS} ${PHP_CFLAGS}"
108108
109-
AC_CHECK_LIB(php5, php_embed_init,[ PHP_LIBS="-lphp5" ],[ AC_MSG_ERROR([Not found php embeded library]) ])
110-
109+
AC_CHECK_LIB(php5, php_embed_init,[ PHP_LIBS="-lphp5" ], [
110+
AC_CHECK_LIB(php7, php_embed_init,[ PHP_LIBS="-lphp7" ], [ AC_MSG_ERROR([Not found php embeded library]) ])
111+
])
112+
dnl AC_CHECK_LIB(php7, php_embed_init,[ PHP_LIBS="-lphp7" ], [ AC_MSG_ERROR([Not found php embeded library]) ]))
113+
AC_CHECK_LIB(php7, zend_signal_startup,[ AC_DEFINE(HAVE_ZEND_SIGNAL_STARTUP,[1],[zend_signal_startup are available]) ])
111114
LIBS="${_save_php_libs}"
112115
LDFLAGS="${_save_php_ldflags}"
113116
CFLAGS="${_save_php_cflags}"
@@ -117,7 +120,7 @@ AC_HELP_STRING([--with-php_lib@<:@=DIR@:>@], [PHP lib subdirectory if different
117120
118121
PHP_VERSION=`$PHP_CONFIG --version`
119122
120-
AC_DEFINE(HAVE_PHP,1,[Define to 1 if PHP libraries are available])
123+
AC_DEFINE(HAVE_PHP,[1],[Define to 1 if PHP libraries are available])
121124
122125
CFLAGS="${CFLAGS} ${PHP_CFLAGS}"
123126
found_php="yes"

php_embeded.c

+23-13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
* https://www.amazon.fr/Advanced-PHP-Programming-George-Schlossnagle/dp/0672325616
7474
*/
7575

76+
/* upgrading to php7
77+
* https://wiki.php.net/phpng-upgrading
78+
* https://www.programmersought.com/article/42361486581/
79+
*/
80+
7681
#include "php_embeded.h"
7782
#include "ext/standard/php_standard.h"
7883

@@ -81,27 +86,22 @@
8186
#error "Need PHP version >= 5.5 to compile this file"
8287
#endif
8388

84-
8589
/******************************************************************************
8690
* *
8791
* Function: php_embed_eval_string *
8892
* *
8993
* Purpose: eval php script string transmit in code. *
9094
* *
9195
******************************************************************************/
92-
zval *php_embed_eval_string(char *code, zval *retval_ptr, char *string_name TSRMLS_DC)
96+
int php_embed_eval_string(char *code, zval *retval, char *string_name TSRMLS_DC)
9397
{
94-
zval * retval;
95-
ALLOC_INIT_ZVAL(retval);
96-
9798
zend_try {
98-
if (SUCCESS == zend_eval_string(code, retval, string_name TSRMLS_CC))
99-
return retval;
99+
if (SUCCESS == zend_eval_string(code, retval, string_name TSRMLS_CC)) return SUCCESS;
100100
} zend_catch {
101101

102102
} zend_end_try();
103103

104-
return retval;
104+
return FAILURE;
105105
}
106106

107107

@@ -112,10 +112,9 @@ zval *php_embed_eval_string(char *code, zval *retval_ptr, char *string_name TSRM
112112
* Purpose: execute filename script. *
113113
* *
114114
******************************************************************************/
115-
zval * php_embed_execute(char *filename TSRMLS_DC)
115+
int php_embed_execute(char *filename, zval *retval TSRMLS_DC)
116116
{
117117
int ret = 0;
118-
zval *retval = NULL;
119118
zend_file_handle zfd;
120119

121120
zfd.type = ZEND_HANDLE_FILENAME;
@@ -125,9 +124,9 @@ zval * php_embed_execute(char *filename TSRMLS_DC)
125124
zfd.opened_path = NULL;
126125
zend_try {
127126
if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, &retval, 1, &zfd))
128-
if (retval) return retval;
127+
return SUCCESS;
129128
} zend_end_try();
130-
return retval;
129+
return FAILURE;
131130
}
132131

133132

@@ -151,7 +150,7 @@ static const zend_function_entry my_additional_functions[] = {
151150
*/
152151
int php_embed_minit(const char* hardcoded_ini PTSRMLS_DC)
153152
{
154-
#ifdef ZTS
153+
#if defined(ZTS) && PHP_VERSION_ID < 70400
155154
void ***tsrm_ls = NULL;
156155
#endif
157156
int ini_entries_len = 0;
@@ -168,11 +167,22 @@ int php_embed_minit(const char* hardcoded_ini PTSRMLS_DC)
168167
#endif
169168

170169
#ifdef ZTS
170+
#if PHP_VERSION_ID >= 70400
171+
php_tsrm_startup();
172+
#else
171173
tsrm_startup(1, 1, 0, NULL);
172174
tsrm_ls = ts_resource(0);
173175
*ptsrm_ls = tsrm_ls;
174176
#endif
177+
#endif
175178

179+
#if PHP_VERSION_ID >= 70000 && defined(ZEND_SIGNALS)
180+
#if HAVE_ZEND_SIGNAL_STARTUP
181+
zend_signal_startup();
182+
#elif defined(ZTS)
183+
#error PHP is built with thread safety and broken signals.
184+
#endif
185+
#endif
176186
if (hardcoded_ini!=NULL)
177187
{
178188
ini_entries_len = strlen(hardcoded_ini);

php_embeded.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,22 @@
3535
#include "TSRM.h"
3636
#include "zend_exceptions.h"
3737

38+
#if PHP_VERSION_ID >= 70000
39+
#define PTSRMLS_DC
40+
#endif
41+
42+
/* php 8 */
43+
#ifndef TSRMLS_CC
44+
#define TSRMLS_CC
45+
#define TSRMLS_DC
46+
#define TSRMLS_D void
47+
#define TSRMLS_C
48+
#endif
49+
50+
int php_embed_minit(const char* hardcoded_ini PTSRMLS_DC);
3851
int php_embed_rinit(TSRMLS_D);
39-
zval * php_embed_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC);
40-
zval * php_embed_execute(char *filename TSRMLS_DC);
52+
int php_embed_eval_string(char *code, zval *retval, char *string_name TSRMLS_DC);
53+
int php_embed_execute(char *filename, zval *retval TSRMLS_DC);
4154
void php_embed_mshutdown(TSRMLS_D);
4255
void php_embed_rshutdown(TSRMLS_D);
4356

0 commit comments

Comments
 (0)